i am passing an array of items to the rails create scaffold from a form
(checkboxes) e.g
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??
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) %>
<% 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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.