ruby on rails - Search bar not working on some pages Sunspot Solr -
i added search bar header, every page in application has one. however, search bar works on home page , index pages. when go contact page (just example) doesn't work. have tried redirecting search url, nothing seems work. suggestions?
search_controller.rb (controller)
class searchcontroller < applicationcontroller def index @search = sunspot.search [dairy, drink] fulltext params[:search] end if @search.results.any? @results = @search.results else return redirect_to request_path end end end
search.rb (model)
class search < activerecord::base attr_accessible :title searchable autosuggest :search_title, :using => :title end end
_searchbarheader.html.erb (search bar view)
<%= form_tag search_index_path, :method => :get %> <%= text_field_tag :search, params[:search], style:"width:300px; height:30px;" %> <%= submit_tag "search!", :name => nil, class: "btn btn-default"%> <% end %>
_header.html.erb (header view)
<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>
my searchbar rendered header, , header rendered app. thank help. still learning how rails , solr works together.
remove form tags in _header.html.erb wrapping search bar. form_tag helper in _searchbarheader.html.erb render form tags well. so, have now, html output have nested forms. i'm not sure that's issue, it's incorrect html cause problems depending on else on page, e.g., other forms.
Comments
Post a Comment