ruby on rails - Ransack's collection_select and HABTM return undefined method -
i've been looking on code on , on again , can't see problem.
i have 2 models person , credential. have habtm relationship.
person
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
credential
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
and here's form in people index.html.erb:
<%= search_form_for @search, :class => 'no-bottom-margin form-inline' |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 %>
and lastly, error i'm getting.
undefined method `credentials_id_eq' #<ransack::search:0x00000105aa4f28>
so if make model's attribute unracksackable so:
unransackable_attributes = ["id", "created_at", "updated_at"]
you can't use ransack's :model_attribute_predicate function particular attribute. so, :credentials_id_eq
it's pretty obvious now, wanted to hide id user when making custom query, make available myself. changed ransack function :credentials_name_cont
, worked fine. also, removing id
list of unracksackable attributes work.
Comments
Post a Comment