Gary_Simons-HUkWsRAlkkg@public.gmane.org
2005-Apr-28 03:34 UTC
Scaffolding for associations?
I am new to Rails and very excited about the notion of "scaffolding" that automatically generates a default application that you can then successively refine. In the case of a single database table that is not related to any others, I have had the joy of developing a complete default editor and viewer within minutes by writing just a few lines of code. But when expanding the application to include a second table that is associated, I haven''t been able to complete the joy. I''ve added the belongs_to and has_many declarations in the respective model files, but have not gotten anything in the default "edit" view for setting the relationship or in the default "show" view for navigating the link. Before I conclude that Rails isn''t able to create a complete editor and viewer by means of the default scaffolding, I want to check with those who are more experienced to ensure that I haven''t missed something. If it isn''t built in, does anybody know of a generator that would create such a thing? Thanks, Gary Simons
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Gary_Simons-HUkWsRAlkkg@public.gmane.org wrote:> experienced to ensure that I haven''t missed something. If it isn''t built > in, does anybody know of a generator that would create such a thing?No, it''s not built in, as it would be complicated to make it work in every case, especially if there are complicated relations. There is a scaffold generator, which builds a lot of code for you. All you need to do after specifying your model relations then is to add a loop and display items from the relation in the view template. I thought there were a few tutorials that show this... - -- David Morton Maia Mailguard server side anti-spam/anti-virus solution: http://www.maiamailguard.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCcGibSIxC85HZHLMRAh9ZAJ9px049kE8rA9FCF6uuT+dxHvRkFQCgmOOe wXUBXNBoq7/t7l875eC4eSQ=nA1M -----END PGP SIGNATURE-----
Take a look at the list archives. There was a fairly detailed discussion of this in the last two weeks. Someone also new to rails wrote a post very similar to yours and some reasons for why this hasn''t been done and why it shouldn''t be done were discussed. In short, scaffolding is to let you fill in domain objects that interact with the domain objects you''re writing code for in order to prevent having to debug two objects at once (which leads to code that only works by coincidence). It''s *not* for production, and as has been discussed here previously, it''s not secure (this may have been resolved, or deliberately left to discourage production use. I don''t remember). Brian On 4/28/05, David Morton <mortonda-0/IDydmJJnNeoWH0uzbU5w@public.gmane.org> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Gary_Simons-HUkWsRAlkkg@public.gmane.org wrote: > > > experienced to ensure that I haven''t missed something. If it isn''t built > > in, does anybody know of a generator that would create such a thing? > > No, it''s not built in, as it would be complicated to make it work in > every case, especially if there are complicated relations. > > There is a scaffold generator, which builds a lot of code for you. All > you need to do after specifying your model relations then is to add a > loop and display items from the relation in the view template. > > I thought there were a few tutorials that show this... > > - -- > David Morton > Maia Mailguard server side anti-spam/anti-virus solution: > http://www.maiamailguard.com > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.2.5 (GNU/Linux) > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org > > iD8DBQFCcGibSIxC85HZHLMRAh9ZAJ9px049kE8rA9FCF6uuT+dxHvRkFQCgmOOe > wXUBXNBoq7/t7l875eC4eSQ> =nA1M > -----END PGP SIGNATURE----- > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- The years ahead pick up their dark bags. They move closer. There''s a slight rise in the silence then nothing. -- (If you''re receiving this in response to mail sent to bluczkie-OM76b2Iv3yLQjUSlxSEPGw@public.gmane.org, don''t be concerned This is my new address, but mail will be forwarded here indefinitely)
One advantage, however, wasn''t mentioned in last week''s postings: Building a simple drop-box in to the scaffold for any model that uses belongs_to would be an effective teaching tool for newcomers to see how to use the FormHelper class. In my experience, it would also "snap together" about half of the models I create (e.g. simple look-ups or status type fields that use a one-to-many relationship). Duane Johnson (canadaduane) On Apr 28, 2005, at 12:45 PM, Brian L. wrote:> Take a look at the list archives. There was a fairly detailed > discussion of this in the last two weeks. Someone also new to rails > wrote a post very similar to yours and some reasons for why this > hasn''t been done and why it shouldn''t be done were discussed. > > In short, scaffolding is to let you fill in domain objects that > interact with the domain objects you''re writing code for in order to > prevent having to debug two objects at once (which leads to code that > only works by coincidence). It''s *not* for production, and as has been > discussed here previously, it''s not secure (this may have been > resolved, or deliberately left to discourage production use. I don''t > remember). > > Brian > > > On 4/28/05, David Morton <mortonda-0/IDydmJJnNeoWH0uzbU5w@public.gmane.org> wrote: >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> Gary_Simons-HUkWsRAlkkg@public.gmane.org wrote: >> >>> experienced to ensure that I haven''t missed something. If it isn''t >>> built >>> in, does anybody know of a generator that would create such a thing? >> >> No, it''s not built in, as it would be complicated to make it work in >> every case, especially if there are complicated relations. >> >> There is a scaffold generator, which builds a lot of code for you. >> All >> you need to do after specifying your model relations then is to add a >> loop and display items from the relation in the view template. >> >> I thought there were a few tutorials that show this... >> >> - -- >> David Morton >> Maia Mailguard server side anti-spam/anti-virus solution: >> http://www.maiamailguard.com >> -----BEGIN PGP SIGNATURE----- >> Version: GnuPG v1.2.5 (GNU/Linux) >> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org >> >> iD8DBQFCcGibSIxC85HZHLMRAh9ZAJ9px049kE8rA9FCF6uuT+dxHvRkFQCgmOOe >> wXUBXNBoq7/t7l875eC4eSQ>> =nA1M >> -----END PGP SIGNATURE----- >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > -- > The years ahead pick up their dark bags. > They move closer. There''s a slight rise in the silence > > then nothing. > -- > (If you''re receiving this in response to mail sent to > bluczkie-OM76b2Iv3yLQjUSlxSEPGw@public.gmane.org, don''t be concerned This is my new address, > but mail will be forwarded here indefinitely) > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >