I have a error with page updating
ActiveRecord::AssociationTypeMismatch in Admin::PagesController#update
Page(#64407864) expected, got String(#17069256)
app/controllers/admin/pages_controller.rb:36:in `update’
line 36 of Admin::PagesController update
if @page.update_attributes(params[:page])
page.rb
class Page < ActiveRecord::Base
has_and_belongs_to_many :related, :class_name => "Page", :join_table => "pages_related", :foreign_key => "page_id", :association_foreign_key => "related_id"
end
_form.html.erb
<%= f.select :related, Page.all.delete_if {|p| p.id == f.object.id}.collect {|p| [p.title, p.id]}, { :include_blank => true }, {:multiple => "multiple"} %>
up:
thanks, its working, but now Ive got the error with new Page creating
Called id for nil, which would
mistakenly be 4 — if you really
wanted the id of nil, use object_idExtracted source (around line #70):
70: <%= f.select :related_ids,
Page.all.delete_if {|p| p.id ==
f.object.id}.collect {|p| [p.title,
p.id]}, { :include_blank => true },
{:multiple => “multiple”, :class =>
“select_multiple”} %>
Your
selectfield should be calledrelated_ids, since it will be passing back the IDs for the selected objects, not the actual objects themselves.