[Rails] HABTM and collection_select

Juan Medín juanmedin at gmail.com
Thu Aug 17 18:50:05 GMT 2006


Hi,

I'm trying to use collection_select with a habtm relationship. Let's say 
you have two tables: books and authors with a many-to-many relationship.

Is there any way in rails to render something like selection boxes for 
each author, so that the user can change them?

I tried this (and several more variations) but it doesn't work:

<% for @author in @book.authors %>
<%= collection_select("author[]", "author_id", @authors, :id, 
:full_name) %>
<% end %>

Is it possible to use collection select for this ?

Thanks in advance,

- Juancho

-- 
Posted via http://www.ruby-forum.com/.


More information about the Rails mailing list