On Tue, Jun 1, 2010 at 4:49 AM, Matias Niemela <[email protected]> wrote: > Hey Guys. > > I'm very new with rails and I've been building a CMS application > backend. > > All is going well, but I would like to know if this is possible? > > Basically I have two models: > > @page { id, name, number } > > @extended_page { id, page_id, description, image } > > The idea is that there are bunch of pages but NOT ALL pages have > extended_content. In the event that there is a page with extended > content then I want to be able to have a form that allows for editing > both of them. > > In the controller: > > @page = Page.find(params[:id]) > @extended= Extended.find(:first, :conditions => ["page_id = > ?",@page.id]) > @combined = ... #merge the two somehow > > So in the view: > > <%- form_for @combined do |f| %> > > <%= f.label :name %> > <%= f.text_field :name %> > > ... > > <%= f.label :description %> > <%= f.text_field :description %> > > <% end > > > This way in the controller, there only has to be one model that will be > updated (which will update to both). > > Is this possible?
Yes it is ! First of all, you should use associations so that one Page has_many :extendeds (this is where you see that you should find a better name !). Then, you should check out this railscast: http://railscasts.com/episodes/196-nested-model-form-part-1 It explains exactly what you are trying to achieve. -- Gael Muller -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

