This should be a really simple thing, I just haven''t figured out how to
do it yet....
I have two models with a has_many, :through => relationship:
class Source < ActiveRecord::Base
has_many :authorships
has_many :authors, :through => :authorships
class Author < ActiveRecord::Base
has_many :authorships
has_many :sources, :through => :authorships
class Authorship < ActiveRecord::Base
belongs_to :source
belongs_to :author
I''m not sure how to create a form for this. My sources/new form has a
nested form for authorship that currently looks like this (I''m
following
the instructions Ryan Bates gives in _Advanced Rails Recipes_ for
dealing with multiple models in one form):
<div class="authorship">
<% new_or_existing = authorship.new_record? ? ''new'' :
''existing'' %>
<% prefix = "source[#{new_or_existing}_authorship_attributes][]"
%>
<% fields_for prefix, authorship do |authorship_form| %>
<p>
<%= authorship_form.text_field :author_id %>
<%= link_to_function "remove",
"$(this).up(''.authorship'').remove()" %>
</p>
<% end %>
</div>
This works just fine, and saves the data just fine, but obviously I
would like to be able to type in author.name instead of :author_id. I
would also be happy to use collection_select here, but haven''t been
able
to figure out how to do that with a has_many, :through => relationship.
Thank you!
--
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?hl=en
-~----------~----~----~----~------~----~------~--~---