Frederick Cheung wrote in post #984616:
> That sounds like you've got an unsaved metered_service somewhere (eg
> by doing premise.metered_services.build)
> Fred

Yep, that's true.  I based my code on the canonical blog posts / 
comments example, so in views/premises/edit.html.erb, I wrote:

<%= form_for([@premise,
@premise.metered_services.build(:account_identifier => "gas")]) do |f|
%>
  <%= f.submit "add gas account" %>
<% end %>

... and it clearly calls build() whenever it renders the page.  But this
leads to two questions:

* (Curiosity:) How did render(... :collection) know about the newly
created metered_service without an ID?  I know that
premise.metered_services.build will create a new record, but it appears
that the new record doesn't appear on the premises.metered_services list
until it's saved.

* (Necessity:) Assume the user is looking at
views/premises/edit.html.erb.  I want a button that says "add
metered_service to the current premise".  What's the right way to do
that?  (Clearly, I haven't made friends with form_for() just yet.)

TIA.

- ff

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to