It looks like you are trying to store the results of an association
(has_many, habtm) in a field on a database table.
For example, if you are saving a user that has many roles, instead of having
a "roles" field on your table, you would have a separate roles table
and a
roles_users table. The models would look like:
User - has_and_belongs_to_many :roles
Roles - has_and_belongs_to_many :users
The view would look like:
<% for role in Role.find(:all) %>
<input type="checkbox" name="role_ids[]"
value="<%= role.id %>"><br/>
<% end %>
In the controller, on the create/update you use the convenient
"role_ids"
method of the user object, like:
@user=User.new(params[:user])
@user.role_ids = params[:role_ids]
Hope that helps.
On 10/18/06, mmaki
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> i am passing an array of items to the rails create scaffold from a form
> (checkboxes) e.g
>
> <input type="checkbox" id="table_field"
name="table[field][]"
> value="my_value">
>
> this works, and when i check my database table the field contains the
> following:
>
> ---
> - 1st value
> - 2nd value
> - 3rd value
> etc.....
>
> so when i come to use these values i get the first value which is
''---''
> the second value as ''- 1st value'' etc.. obviously i want
the first value
> to be ''1st value'', second value ''2nd
value'' etc.
>
> any body else experienced this, and have a solution??
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---