I have the following Models:
===class Document < ActiveRecord::Base
has_many :document_topics, :dependent => true
has_many :topics, :through => :document_topics
end
class Topic < ActiveRecord::Base
has_many :document_topics, :dependent => true
has_many :documents, :through => :document_topics
end
===
and the following is and excert from the document controller:
===def update
@document = Document.find(params[:id])
if @document.update_attributes(params[:document])
flash[:notice] = ''Document was successfully updated.''
redirect_to :action => ''show'', :id => @document
else
render :action => ''edit''
end
end
===
I''m trying to do the following in a document view:
===<% Topic.find(:all).each do |topic| %>
<input type="checkbox" name="document[topic_ids][]"
value="<%=
topic.id %>" <% if @document.topics.include?(topic) %>
checked="checked"
<% end %> />
<%= topic.title %>
<% end %>
===
But im getting the following error when I try to update a document:
===undefined method `topic_ids='' for #<Document:0x35c46f0>
===
I thought ''topic_ids'' was automatically generate? What am I
doing wrong?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---