Meta_Search Rails - 搜索我的模型方法
我有一个 User
类,其模型如下。我希望能够使用 meta_search 按全名搜索用户(即 John Smith
而不是 John
或 Smith
(在单独的字段中) ))。
class User < ActiveRecord::Base
search_methods :fullName
def fullName
firstName + " " + lastName
end
end
在我看来:
<%= form_for @search, :url => users_path, :html => {:method => :get} do |f| %>
<%= f.label :fullName %> <%= f.text_field :fullName_equals %>
<%= f.submit "Search Users" %>
<% end %>
根据 文档 我应该能够使用它,但它不断引发异常:
NoMethodError in UsersController#index
undefined method `fullName' for #<ActiveRecord::Relation:0x#####>
有什么想法我哪里出错了吗?
I have a User
class whose model is as below. I want to be able to use meta_search to search for a user by fullName, (i.e. John Smith
rather than John
or Smith
(in separate fields)).
class User < ActiveRecord::Base
search_methods :fullName
def fullName
firstName + " " + lastName
end
end
And in my view:
<%= form_for @search, :url => users_path, :html => {:method => :get} do |f| %>
<%= f.label :fullName %> <%= f.text_field :fullName_equals %>
<%= f.submit "Search Users" %>
<% end %>
As per the documentation I should be able to use this, but it keeps raising an Exception:
NoMethodError in UsersController#index
undefined method `fullName' for #<ActiveRecord::Relation:0x#####>
Any ideas where I'm going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
attr_accessor :full_name
添加到您的模型中。Add
attr_accessor :full_name
to your model.