Rails: Scaffold to automatically do one-to-many relationship

Dan Rosenstark picture Dan Rosenstark · Feb 2, 2009 · Viewed 15.9k times · Source

Not sure if I'm reading this right, but it seems like Scaffold will not do a one-to-many relationship in its entirety. For instance, if I create messages with scaffold and then I want comments on those messages (one message -> many comments), I have to go through and change everything. For instance, I have to change this in the comment's new view

<% form_for(@comment) do |f| %>

to this

<% form_for([@message, @comment]) do |f| %>

and then change the Action to set up the @message var... amongst other things.

This cannot currently be done automatically with Scaffold, right?

Answer

Chirantan picture Chirantan · Feb 2, 2009

Yes. Scaffold works for a model and related controller. It does not take care of or work with relationships.

Scaffold's primary objective is to get CRUD going on a model using a controller and related views. That's all. Any other requirement like relationships has to be coded manually.