Ok, whats the proper way to name things in Rails? When I do script/generate scaffold profile, it creates everything as plural (profiles). Is there a reason that the scaffold command does that? When I create everything myself, like script/generate model profile, it just creates it as profile, the singular form. So which is the proper way of doing it? Do the database tables need to be singular or plural? Do the models needs to be singular or plural? (user vs users or profile vs profiles) Same with the controllers, views, helpers, fixtures, etc. I want things to be consistant, so I''d rather just use one terminology. If plural is the way to go, then I''d rather use that for everything. Of course, there are cases where plural doesn''t make sense, but in most cases I think plural is the way to go. I would appreciate if someone in the know would comment on this. Thank you. P.S. this is a bit off topic, but is there a way to "ungenerate" something that you''ve generated? I ran the generate scaffold command it created all these files for me. Is there an easy way to remove them? that would be a greate script to have as part of rails. Cause I do things all the time and I want to undo them. -- - Ramin http://www.getintothis.com/blog _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 5/20/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Do the database tables need to be singular or plural? > Do the models needs to be singular or plural? (user vs users or profile vs > profiles) > Same with the controllers, views, helpers, fixtures, etc.Models should be singular;: script/generate model User Controllers should be plural: script/generate controller Users All other objects in question get generated automatically when you create your model/controller so no need to worry about them.> P.S. this is a bit off topic, but is there a way to "ungenerate" something > that you''ve generated?If you are using a source control system, like Subversion, you could revert back to a pristine state. Josh
On May 20, 2005, at 11:47 AM, Ramin wrote:> P.S. this is a bit off topic, but is there a way to "ungenerate" > something that you''ve generated? I ran the generate scaffold > command it created all these files for me. Is there an easy way to > remove them? that would be a greate script to have as part of > rails. Cause I do things all the time and I want to undo them.Have a look at script/destroy. -Dane
Ramin wrote:> Ok, whats the proper way to name things in Rails? When I do > script/generate scaffold profile, it creates everything as plural > (profiles). Is there a reason that the scaffold command does that? > When I create everything myself, like script/generate model profile, > it just creates it as profile, the singular form. So which is the > proper way of doing it? >Well this in an issue in part of what you want your url to look like mysite.com/profile or mysite.com/profiles given that for a single profile /profile/1 is prettier than /profiles/view/1 but for a list /profiles is prettier than /profile i opt for plural personally... if you want to get into rewriting with routing that would work... but I found that a lot of rewriting with routes makes maintaining cache sweeper a real pain.> Do the database tables need to be singular or plural?plural> Do the models needs to be singular or plural? (user vs users or > profile vs profiles)singular script/generate model show would by default look in a table called shows> Same with the controllers, views, helpers, fixtures, etc. >see above for controllers... the views and helpers are created when you do script/generate controller profiles not that some things break realted to pluralization dont work without patching... ( try creating a controller called address see how far you get... )> I want things to be consistant, so I''d rather just use one > terminology. If plural is the way to go, then I''d rather use that for > everything. Of course, there are cases where plural doesn''t make > sense, but in most cases I think plural is the way to go. >if you want an ''easy'' rails experience go with plural database table names id as the primary key and if a profile belong to an entry in the users table have the foreign key be user_id there is a lot about this on the wiki but I''m not in much of a mood to go digging it up... somehow in may laziness typing all this felt easier... there is also a gotchas section of reserved words... definately check that out... _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks guys. Your input and feedback is greatly appreciated. I think I understand better now. I did notice script/destroy but couldn''t figure out how to use it. I looked in the rails API, but I dont think it has any documentation about those scripts. Is there a place where I can read about the different script generators? On 5/20/05, Dane Jensen <jensen-hTe+RANN9c/LSiWjCY9aRNBPR1lH4CV8@public.gmane.org> wrote:> > > On May 20, 2005, at 11:47 AM, Ramin wrote: > > > P.S. this is a bit off topic, but is there a way to "ungenerate" > > something that you''ve generated? I ran the generate scaffold > > command it created all these files for me. Is there an easy way to > > remove them? that would be a greate script to have as part of > > rails. Cause I do things all the time and I want to undo them. > > Have a look at script/destroy. > > -Dane >-- - Ramin http://www.getintothis.com/blog _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 5/20/05, Josh Knowles <joshknowles-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 5/20/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Do the database tables need to be singular or plural? > > Do the models needs to be singular or plural? (user vs users or profile vs > > profiles) > > Same with the controllers, views, helpers, fixtures, etc. > > Models should be singular;: > script/generate model User > > Controllers should be plural: > script/generate controller Users? Is this by convention, or does something in rails depend on this? I use singular controller, as does the "Rolling on Rails" example, from which I and by the mail I read here, so have many others.
>> Controllers should be plural: >> script/generate controller Users >> > > ? Is this by convention, or does something in rails depend on this? > I use singular controller, as does the "Rolling on Rails" example, > from which I and by the mail I read here, so have many others.It is neither required nor is it necessarily by convention. Controllers should be named according to "what makes sense" in the situation. "Login", "Users", "MyAccount", and "Accounts" are all valid names. There is no dependency on a particular naming convention (other than the camelized wording in the class name, and the underscored name when accessing it in the URL). Duane Johnson (canadaduane)