Forum: Ruby on Rails Multiple select issue with a HABTM relationship using Rails 4

9d7c3b26fc9313c3be85a9323652ae72?d=identicon&s=25 Diego Couto (Guest)
on 2013-07-20 13:01
(Received via mailing list)
Although the code seems to be right, when I try to send the form, the
values of the multiple select aren't being sent.If I just remove the
multiple option, everything works as expected considering just one
value,
but it's important to store more than one tag per transaction.

Do you have any ideas about what could be happening here?

*Model*

*Transaction.rb*

class Transaction < ActiveRecord::Base
    has_and_belongs_to_many :tags

*Tag.rb*

class tag < ActiveRecord::Base
    has_and_belongs_to_many :transactions

*View*

<%= form.collection_select :tag_ids, @tags, :id, :name, {},
    {:multiple => true} %>

*Result:*

<select id="transaction_tag_ids" multiple="multiple"
name="transaction[tag_ids][]">
    <option value="1">..</option>
</select>
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2013-07-20 16:28
(Received via mailing list)
On Fri, Jul 19, 2013 at 5:52 AM, Diego Couto <diego.gcouto@gmail.com>
wrote:
> Although the code seems to be right, when I try to send the form, the values
> of the multiple select aren't being sent.

Are you sure about that? Check the log output from submitting the
form.

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.