On 21 July 2013 18:28, James Gray <zaa...@gmail.com> wrote:
> Hi all,
>
> In my controller I am doing the following to populate a nested form for a
> has_many through association:
>
>     def new
>        @specification = Specification.new
>
>     Component.find_each.each do |component|
>       @specification.component_specifications.build(:component_id =>
> component.id)

Don't use .new or .build in the view, do it in the controller so that
everything is prepared before rendering the view.  The view code
should only be concerned with displaying the data.

>     end
>
> The idea being whenever someone creates or edits a form, it will be
> populated with all components at that time so that when they save those
> components that specification will be associated with the newly created
> specification. The problem I am having is I can't work out how to pass
> component name to display in my form for the as yet nonexistent
> component_specification as it is not accessible through the
> ComponentSpecification model.

I have no idea what you mean by the last sentence.  But as I said
above you should be doing this in the controller anyway.

>
> My models:
>
> class Specification < ActiveRecord::Base

You said in the title ActiveModel, (well actually you said activemodel
wihch would be something different again) but I see you meant
ActiveRecord.  When asking questions it is important to get the
details right.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtktCQg_B%2B-AJYgg6B9oHJMwGJKUSuC8sGEHiqFKsTW4w%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to