Ruby on Rails Sunday, January 27, 2013

Here's the gist of my problem: (using formtastic)

Models:

Person (has_one :color)
Color

So I have this database full of already populated Color entries via a
whole separate controller + views for creating Colors. When creating a
person, I want to be able to select a Color object without creating it.
So I'm not looking for something such as:

= semantic_form_for @person do |form|
= form.input :name
= semantic_fields_for :color do |c|
= c.input :hex
= form.actions :submit

This would create a Color model to be associated with a Person. I want
something more along the lines of this functionality:

= semantic_form_for @person do |form|
= form.input :name
= form.input :color, :as => :select, :collection => @colors

so that I can select a Color that is already in the database.

I know there is a more rails-way to do this rather than having a "color
code" attribute and then perform a query to locate a Color that has the
corresponding color code. Any suggestions are much appreciated!

Thanks!

- Mac

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment