2012-06-24 2 views
0

내 태양 흑점 검색 기능 (sunspot_rails 보석은) 내 인덱스보기에서 잘 작동하지만 내 쇼를 복제 할 때 내 검색 나누기를 ... 볼잘못된 컨트롤러 동작을 나타내므로 검색 기능이 실패합니까?

보기/supplierproducts/show.html.erb

<%= form_tag supplierproducts_path, :method => :get, :id => "supplierproducts_search" do %> 
    <p> 
    <%= text_field_tag :search, params[:search], placeholder: "Search by SKU, product name & EAN number..." %> 
    </p> 
    <div id="supplierproducts"><%= render 'supplierproducts' %></div> 
<% end %> 

자산/자바 스크립트는/

$(function() { 
    $('#supplierproducts th a').live('click', 
    function() { 
     $.getScript(this.href); 
     return false; 
    } 
); 

    $('#supplierproducts_search input').keyup(function() { 
    $.get($("#supplierproducts_search").attr("action"), $("#supplierproducts_search").serialize(), null, 'script'); 
    return false; 
    }); 
}); 

보기/supplierproducts/우 application.js w.js.erb/_supplierproducts.hmtl.erb

<%= hidden_field_tag :direction, params[:direction] %> 
<%= hidden_field_tag :sort, params[:sort] %> 
<table class="table table-bordered"> 
    <thead> 
    <tr> 
     <th><%= sortable "sku", "SKU" %></th> 
     <th><%= sortable "name", "Product name" %></th> 
     <th><%= sortable "stock", "Stock" %></th> 
     <th><%= sortable "price", "Price" %></th> 
     <th><%= sortable "ean", "EAN number" %></th> 
    </tr> 
    </thead> 
    <% for supplierproduct in @supplier.supplierproducts %> 
    <tbody> 
    <tr> 
     <td><%= supplierproduct.sku %></td> 
     <td><%= supplierproduct.name %></td> 
     <td><%= supplierproduct.stock %></td> 
     <td><%= supplierproduct.price %></td> 
     <td><%= supplierproduct.ean %></td> 
    </tr> 
    </tbody> 
    <% end %> 
</table> 

컨트롤러/supplierproducts_controller.rb

class SupplierproductsController < ApplicationController 

helper_method :sort_column, :sort_direction 

    def show 
    @supplier = Supplier.find(params[:id]) 
    @search = @supplier.supplierproducts.search do 
     fulltext params[:search] 
    end 
    @supplierproducts = @search.results 
    end 
end 

private 

    def sort_column 
    Supplierproduct.column_names.include?(params[:sort]) ? params[:sort] : "name" 
    end 

    def sort_direction 
    %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc" 
    end 

모델/supplierproduct

$('#supplierproducts').html('<%= escape_javascript(render("supplierproducts")) %>'); 

전망/supplierproducts. rb

class Supplierproduct < ActiveRecord::Base 
    attr_accessible :ean, :name, :price, :sku, :stock, :supplier_id 
    belongs_to :supplier 

    validates :supplier_id, presence: true 

    searchable do 
    text :ean, :name, :sku 
    end 
end 

visiting show.html.erb는 정상적으로 작동합니다. 로그 쇼 :

Started GET "/supplierproducts/2" for 127.0.0.1 at 2012-06-24 13:44:52 +0200 
Processing by SupplierproductsController#show as HTML 
    Parameters: {"id"=>"2"} 
    Supplier Load (0.1ms) SELECT "suppliers".* FROM "suppliers" WHERE "suppliers"."id" = ? LIMIT 1 [["id", "2"]] 
    SOLR Request (252.9ms) [ path=#<RSolr::Client:0x007fa5880b8e68> parameters={data: fq=type%3ASupplierproduct&start=0&rows=30&q=%2A%3A%2A, method: post, params: {:wt=>:ruby}, query: wt=ruby, headers: {"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}, path: select, uri: http://localhost:8982/solr/select?wt=ruby, open_timeout: , read_timeout: } ] 
    Supplierproduct Load (0.2ms) SELECT "supplierproducts".* FROM "supplierproducts" WHERE "supplierproducts"."id" IN (1) 
    Supplierproduct Load (0.1ms) SELECT "supplierproducts".* FROM "supplierproducts" WHERE "supplierproducts"."supplier_id" = 2 
    Rendered supplierproducts/_supplierproducts.html.erb (2.2ms) 
    Rendered supplierproducts/show.html.erb within layouts/application (3.3ms) 
    Rendered layouts/_shim.html.erb (0.0ms) 
    User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = 'zMrtTbDun2MjMHRApSthCQ' LIMIT 1 
    Rendered layouts/_header.html.erb (2.1ms) 
    Rendered layouts/_footer.html.erb (0.2ms) 
Completed 200 OK in 278ms (Views: 20.6ms | ActiveRecord: 0.6ms | Solr: 252.9ms) 

하지만 검색을 입력하면 깨집니다. 붙여 넣은 로그에서

Started GET "/supplierproducts?utf8=%E2%9C%93&search=a&direction=&sort=&_=1340538830635" for 127.0.0.1 at 2012-06-24 13:53:50 +0200 
Processing by SupplierproductsController#index as JS 
    Parameters: {"utf8"=>"✓", "search"=>"a", "direction"=>"", "sort"=>"", "_"=>"1340538830635"} 
    Rendered supplierproducts/_supplierproducts.html.erb (2.4ms) 
    Rendered supplierproducts/index.js.erb (2.9ms) 
Completed 500 Internal Server Error in 6ms 

ActionView::Template::Error (undefined method `supplierproducts' for nil:NilClass): 
    10:  <th><%= sortable "ean", "EAN number" %></th> 
    11:  </tr> 
    12: </thead> 
    13:  <% for supplierproduct in @supplier.supplierproducts %> 
    14: <tbody> 
    15:  <tr> 
    16:  <td><%= supplierproduct.sku %></td> 
    app/views/supplierproducts/_supplierproducts.html.erb:13:in `_app_views_supplierproducts__supplierproducts_html_erb___2251600857885474606_70174444831200' 
    app/views/supplierproducts/index.js.erb:1:in `_app_views_supplierproducts_index_js_erb___1613906916161905600_70174464073480' 


    Rendered /Users/Computer/.rvm/gems/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (33.3ms) 
    Rendered /Users/Computer/.rvm/gems/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.9ms) 
    Rendered /Users/Computer/.rvm/gems/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (39.7ms) 

답변

0

는, 탐색 양식이되지 showindex을 타격 할보고, 해당 작업은 @supplier 설정되지 않습니다 로그인을 보여줍니다.

+0

안녕하세요. 나는 쇼 액션을 치고 싶다. 그렇지? 검색 결과는 제공된 공급 업체 (예 : supplierproducts/2)의 결과 만 반환해야합니다. 나는 ** showproducts_path **를 ** show_supplierproducts_path **로 대체하기 위해 ** views/supplierproducts/show.html.erb **를 시도했지만 그 다음 전체 쇼 페이지는 Supplierproducts # show **에서 NameError로 중단됩니다 ** 정의되지 않은 지역 변수 또는 메소드'show_supplierproducts_path '**. 다른 시도로서 나는 쇼를 인덱스 활동에 다시 시도했지만, 검색 시도는이 오류를 제기합니다. ** ID없이 공급자를 찾을 수 없습니다. **. – ChristofferJoergensen

관련 문제