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, (ie 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?
将attr_accessor :full_name
添加到模型中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.