元搜索“NilClass:Class 的未定义方法‘model_name’"用于全球酒吧搜索 [英] MetaSearch "undefined method `model_name' for NilClass:Class" for global bar search
问题描述
我正在使用 Ernie 出色的 MetaSearch,但遇到了一个烦人的问题.
在我的 application.html.erb 中,我有一个搜索字段,就像 StackOverflow 页面顶部的这个一样.
<%= form_for @search, :url =>vagas_path 做 |f|%><%= f.text_field :titulo_or_empresa_user_username_contains %><%= f.submit "", :class =>"搜索按钮", :name =>提交"%><%结束%>
问题是我没有在所有控制器的所有操作中初始化@search,所以当我不在 Vagas#index 时,我收到NilClass:Class 的未定义方法`model_name'"消息.>
最好的解决方案是什么?
============================================
解决方案
<%= form_tag vagas_path, :method =>:get, :id =>'vaga_search' 做 %><%= text_field_tag '搜索[titulo_or_empresa_user_username_contains]' %><%= submit_tag "", :class =>"搜索按钮", :name =>"提交", :id =>'search_submit' %><%结束%>
如果 @search
设置为 nil
,您将收到此错误.确保不是这种情况.
I'm using fantastic MetaSearch by Ernie, but I'm having an annoying issue.
In my application.html.erb I have an search field, just like this one on top of StackOverflow page.
<%= form_for @search, :url => vagas_path do |f| %>
<%= f.text_field :titulo_or_empresa_user_username_contains %>
<%= f.submit "", :class => "search-button", :name => "submit" %>
<% end %>
The problem is that I don't have @search initialized in all actions of all controllers, so when I'm not at Vagas#index I get the "undefined method `model_name' for NilClass:Class" message.
What's the best solution for that?
============================================
Solution
<%= form_tag vagas_path, :method => :get, :id => 'vaga_search' do %>
<%= text_field_tag 'search[titulo_or_empresa_user_username_contains]' %>
<%= submit_tag "", :class => "search-button", :name => "submit", :id => 'search_submit' %>
<% end %>
You would get this error if @search
is set to nil
. Ensure that this is not the case.
这篇关于元搜索“NilClass:Class 的未定义方法‘model_name’"用于全球酒吧搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!