我一遍又一遍地查看我的代码,但我看不到我的问题。
我有两个 Models Person 和 Credential。他们有 HABTM 关系。
人
class Person < ActiveRecord::Base
attr_accessible :credential_ids
has_and_belongs_to_many :credentials
UNRANSACKABLE_ATTRIBUTES = ["id", "hidden_note", "created_at", "updated_at"]
def self.ransackable_attributes auth_object = nil
(column_names - UNRANSACKABLE_ATTRIBUTES) + _ransackers.keys
end
end
凭据
class Credential < ActiveRecord::Base
attr_accessible :description, :name
has_and_belongs_to_many :people
UNRANSACKABLE_ATTRIBUTES = ["id", "created_at", "updated_at"]
def self.ransackable_attributes auth_object = nil
(column_names - UNRANSACKABLE_ATTRIBUTES) + _ransackers.keys
end
end
这是我在 People index.html.erb 中的表格:
<%= search_form_for @search, :class => 'no-bottom-margin form-inline' do |f| %>
%= f.collection_select(:credentials_id_eq , Credential.all, :id, :name )%>
<div class='actions'><%= f.submit "Search", :class => 'btn btn-primary btn-large' %></div>
<% end %>
最后,这是我得到的错误。
undefined method `credentials_id_eq' for #<Ransack::Search:0x00000105aa4f28>