0

我不明白

在 routes.rb 我写过

match 'promotions/search' => 'promotions#search',:as =>:search_promo  ,:via=>:get

在promotions_controller.rb 我添加了:

 def search
  @promotions = Promotion.all
  respond_to do |format|
    format.html # search.html.erb
    format.json { render json: @promotion }
  end
  end

并在视图促销中创建一个文件 search.erb.html

     <!DOCTYPE html>
     <html>
    <head>

       <script  type=text/javascript>
      var geocoder;
        var map;


     function initialize() {
      geocoder = new google.maps.Geocoder();
      var latlng = new google.maps.LatLng(-34.397, 150.644);
      var mapOptions = {
          zoom: 9,
          center: latlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
      }
      map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
      codeAddress();
  }

  function loadScript() {
      var script = document.createElement("script");
      script.type = "text/javascript";
      script.src = "https://maps.googleapis.com/maps/api/js?key=AIzaSyAlDKLvBpApFUJJVjSXbZ-BV40B3xBVtYY&sensor=false&language=it&callback=initialize";
      document.body.appendChild(script);
  }

  window.onload = loadScript;

  function codeAddress() {
      var address = "<%= @promotion.Address %>";
      geocoder.geocode( { 'address': address}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
              map.setCenter(results[0].geometry.location);
              var marker = new google.maps.Marker({
                  map: map,
                  position: results[0].geometry.location
              });
          } else {
              alert('Geocode was not successful for the following reason: ' + status);
          }
      });
  }

  google.maps.event.addDomListener(window, 'load', initialize);

       </script>
       </head>

    <body onload="codeAddress()">
       <div data-role="header"  id="ale" data-theme="a">
      <h1>  View all details </h1>
         <%= link_to 'Home', promotions_url,'data-icon' =>'home','class'=>'ui-btn-      left','data-transition'=>'fade','data-mini'=> 'true' %>
     </div>

     <div data-role="content"    data-theme="b">
         <p id="notice"><%= notice %></p>


      <%= link_to 'Back', promotions_path,'data-role'=>'button','data-inline'=>'true'      %>

          <div class="field">
     <strong><%=p.label :Show_in_google_maps%></strong>
       <div id="map-canvas" style="width: 100%; height:400px"/>
       </div>


    </div>


     </body>
    </html>

在另一页写

<li><%= link_to "Search Promo",search_promo_path,'data-icon'=>'search','data-theme'=>'a','data-mini'=>'true',"data-ajax"=>"false"%></li>

怎么了?

我得到这个错误

在 PromotionsController#show 中的 ActiveRecord::RecordNotFound 找不到带有 id=search 的促销

为什么告诉我显示控制器我想要搜索控制器!帮助

4

1 回答 1

1

您没有发布完整的路线文件,但我想ressources :promotions在您的搜索匹配器之前?切换它们,它应该可以工作。

于 2013-05-27T17:55:18.877 回答