2015-04-01 38 views
0

我在頁眉上添加了一個搜索欄,因此應用程序中的每個頁面都有一個。但是,搜索欄僅適用於主頁和索引頁面。當我轉到我的聯繫頁面時(僅舉例),它不起作用。我嘗試重定向到我的搜索網址,但似乎沒有任何工作。有什麼建議麼?搜索欄在某些頁面上不工作太陽黑子Solr

search_controller.rb(控制器)

class SearchController < ApplicationController 

def index 
    @search = Sunspot.search [Dairy, Drink] do 
    fulltext params[:search] 
end 

if @search.results.any? 
    @results = @search.results 
    else 
    return redirect_to request_path 
    end 
end 

end 

search.rb(模型)

class Search < ActiveRecord::Base 

attr_accessible :title 

searchable do 
    autosuggest :search_title, :using => :title 
end 
end 

_searchbarheader.html.erb(搜索欄視圖)

<%= form_tag search_index_path, :method => :get do %> 
    <%= text_field_tag :search, params[:search], style:"width:300px; height:30px;" %> 
    <%= submit_tag "Search!", :name => nil, class: "btn btn-default"%> 
<% end %> 

_header.html .erb(標題視圖)

<div class="container-fluid"> 
    <%= render 'layouts/brand' unless @skip_brand %> 
    <form class="navbar-form navbar-left"> 
    <%= render 'layouts/searchbarheader' unless @skip_header %> 
    </form> 

    <div id="navbar" class="navbar-collapse collapse"> 
    <ul class="nav navbar-nav navbar-right"> 
     <% if user_signed_in? %> 
     <li><%= link_to current_user.name%></li> 
     <li><a class="glyphicon glyphicon-cog" href="<%=edit_user_registration_path%>"></a></li> 
     <li><%= link_to "Logout", destroy_user_session_path, method: :delete %> </li> 
    <%else%> 
     <li><%= link_to "Login", new_user_session_path %></li> 
     <li><%= link_to "Sign up", new_user_registration_path %></li> 
    </ul>  
    <%end%> 
</div> 

我的搜索欄被渲染到頁眉中,並將頁眉渲染到應用程序中。 謝謝你的幫助。仍在學習軌道和solr如何協同工作。

回答

1

刪除_header.html.erb中的表單標籤,幷包裝搜索欄。 _searchbarheader.html.erb中的form_tag幫助器也會呈現表單標籤。所以,就像你現在所做的那樣,你的HTML輸出將會有嵌套的形式。我不確定這是什麼問題,但它是不正確的HTML,因此可能會導致問題,具體取決於頁面上的其他內容,例如其他表單。