0

我有一个User班级,其模型如下。我希望能够使用 meta_search 按全名搜索用户(即,John Smith而不是JohnSmith(在单独的字段中))。

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#####>

有什么想法我哪里出错了吗?

4

1 回答 1

0

添加attr_accessor :full_name到您的模型中。

于 2011-12-29T13:55:04.730 回答