How to populate a form containing fields related to a "nested" resource from an URL request?
I am using Ruby on Rails 3.0.10 and I would like to populate a form from an URL request. That is, by using a URL as-like (the following is just an - wrong - example) http://website.com/query?user[account_attributes][firstname]=Sample Name
I would like to populate a form field in the requested web page with the user[account_attributes][f开发者_JAVA技巧irstname]
data.
My issue is related to
- using Ruby on Rails "nested" models;
having the following output code related to the field that I would like to "auto"-populate by using the URL query string data;
< input type="text" name="user[account_attributes][firstname]">
How can I do that?
Ok didn't understand the question first. You need to have accepts_nested_attributes for set for account_attributes.
http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes
Then in the new method of the controller you need to populate your model:
User.new(params[:account_attributes])
精彩评论