<Bradley.Kite-93r8m3cLkYPe9wHmmfpqLFaTQe2KTcn/@public.gmane.org>
2005-Aug-08 10:59 UTC
Problems with ./scripts/generate scaffold
Hi all, I''m new to rails after having used perl for most of these things, and am trying to get my head around the generate script for a project playing around with. If I do: ./scripts/generate controller Device I get app/controllers/device_controller.rb where I can then add: scaffold :device However, if I want to actually generate the scaffolding so I can make some changes: ./scripts/generate scaffold Device I get app/controllers/devices_controller.rb (Note the plural on device). The views/templates are also pluralised when generated (as apposed to dynamically imported). Is this due to a lack of my understanding of the correct pluralisation of things? If I rename the generated ones to the non-pluralised ones then things work, so perhaps this is a bug? I''ve searched the archives for any other posts regarding this but have not found any thing regarding ''generate'' Thanks for any help in advance! -- Brad ------------------------------------------------------------------------------------------ Equinox Converged Solutions Tel: +44 (0)1252 405 600 http://www.equinoxsolutions.com Equinox Converged Solutions is a trading name of Synetrix Holdings Limited. IMPORTANT NOTICE: This message is intended solely for the use of the Individual or organisation to whom it is addressed. It may contain privileged or confidential information. If you have received this message in error, please notify the originator immediately. If you are not the intended recipient, you should not use, copy, alter, or disclose the contents of this message. All information or opinions expressed in this message and/or any attachments are those of the author and are not necessarily those of Synetrix Holdings Limited. Synetrix Holdings Limited accepts no responsibility for loss or damage arising from its use, including damage from virus. ------------------------------------------------------------------------------------------- _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Brad, You can specify two arguments when generating a scaffold: script/generate scaffold <model> <controller> Check out the new movie on rubyonrails.com. In there the following is typed IIRC: script/generate scaffold Post Blog A blog is made up of posts. I agree with you that the pluralizing behavior is stupid. I think /item/list, /item/create, and /item/show/12 make more sense and are shorter than /items/list, /items/create, and /items/show/12. I''ll usually add a route to map /items to /item/list. Of course, take my comments with a grain of salt, because I think Rails''s default convention of using plural database table names is profoundly wrong. The class from which we instantiate people is not called People, it''s called Person, but people seem to get locked into thinking about the many rows of data in a table, not the logical entity that the table represents. Regards, Ed -- Transmogrify, LLC * <http://xmog.com>
I tend to agree on the pluralization issue, especially as it pertains to database table names. Do you re-map your models to the singular table names? I''ve seen may places that "it can be done", but have seen any examples in actually doing it. --Ryan On 8/8/05, Ed Watkeys <edw-tIV1OJqwIcc@public.gmane.org> wrote:> Brad, > > You can specify two arguments when generating a scaffold: > > script/generate scaffold <model> <controller> > > Check out the new movie on rubyonrails.com. In there the following is > typed IIRC: > > script/generate scaffold Post Blog > > A blog is made up of posts. I agree with you that the pluralizing behavior > is stupid. I think /item/list, /item/create, and /item/show/12 make more > sense and are shorter than /items/list, /items/create, and /items/show/12. > I''ll usually add a route to map /items to /item/list. > > Of course, take my comments with a grain of salt, because I think Rails''s > default convention of using plural database table names is profoundly > wrong. The class from which we instantiate people is not called People, > it''s called Person, but people seem to get locked into thinking about the > many rows of data in a table, not the logical entity that the table > represents. > > Regards, > Ed > > -- > Transmogrify, LLC * <http://xmog.com> > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I do feel that it adds a lot of complexity and lots of possible bugs, i18n, l10n, etc, issues. Given how the framework came to be, I suppose it''s ok, but I have heard many people complain that this particular convention is a bit heavy-handed. Luckily, it''s possible to map AR subs to table names. It seems that the simpler, cleaner version would be to require the table name to be the class name, and pluralization would be the exception. I''m sure it would be much lighter -- less code to parse and run, less points for security problems, etc. This is one of the bits of Rails that is *too* bound to one person''s way of seeing the world, in my opinion. But hey, if you have total control over everything from the db box to your app boxes and can set the style guide and rules for each detail in your entire application, it works great with no extra work ;) On Aug 8, 2005, at 8:48 AM, Ed Watkeys wrote:> Of course, take my comments with a grain of salt, because I think > Rails''s > default convention of using plural database table names is profoundly > wrong. The class from which we instantiate people is not called > People, > it''s called Person, but people seem to get locked into thinking > about the > many rows of data in a table, not the logical entity that the table > represents._______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Why not just turn pluralisation off in the settings? On 09/08/2005, at 12:30 AM, Ryan Wood wrote:> I tend to agree on the pluralization issue, especially as it pertains > to database table names. Do you re-map your models to the singular > table names? I''ve seen may places that "it can be done", but have seen > any examples in actually doing it. > > --Ryan > > On 8/8/05, Ed Watkeys <edw-tIV1OJqwIcc@public.gmane.org> wrote: > >> Brad, >> >> You can specify two arguments when generating a scaffold: >> >> script/generate scaffold <model> <controller> >> >> Check out the new movie on rubyonrails.com. In there the following is >> typed IIRC: >> >> script/generate scaffold Post Blog >> >> A blog is made up of posts. I agree with you that the pluralizing >> behavior >> is stupid. I think /item/list, /item/create, and /item/show/12 >> make more >> sense and are shorter than /items/list, /items/create, and /items/ >> show/12. >> I''ll usually add a route to map /items to /item/list. >> >> Of course, take my comments with a grain of salt, because I think >> Rails''s >> default convention of using plural database table names is profoundly >> wrong. The class from which we instantiate people is not called >> People, >> it''s called Person, but people seem to get locked into thinking >> about the >> many rows of data in a table, not the logical entity that the table >> represents. >> >> Regards, >> Ed >> >> -- >> Transmogrify, LLC * <http://xmog.com> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Ryan Wood said:> I tend to agree on the pluralization issue, especially as it pertains > to database table names. Do you re-map your models to the singular > table names? I''ve seen may places that "it can be done", but have seen > any examples in actually doing it.It''s pretty easy once someone gives your the right magic incantation. Here are my customization in environment.rb in my 0.13.1 application: ActiveRecord::Base.pluralize_table_names = false ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore CGI::Session::ActiveRecordStore.session_class = RailsSession ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:database_manager => CGI::Session::ActiveRecordStore) The first line tells ActiveRecord to use singular table names. The second tells AR that the primary key in the table foo is foo_id, which allows you to write more clear table definitions: create table foo ( foo_id serial primary key, name text ); create table bar ( bar_id serial primary key, foo_id int references foo, name text ); This example also reinforces why you should give entities singular names. The third line tells Rails to use my custom RailsSession model object for session tracking, because the previous settings cause a conflict in the field names of the standard Session class. The class is Session, so AR normally looks for the table "sessions", with attributes id, session_id, and data. With my settings, which are what anyone with professional experience designing databases would want, AR calls the table for the Session class "session", and it has attributes session_id, session_id, and data. Hmm. Not good. I think "rails_session" is a much better table name anyway, since there''s nothing saying that you don''t have multiple technologies, each with their own session concept, using the same database. I can send you my source for RailsSession if you want. It''s basically a cleaned up, legacy-free version of the stock Session class. The fourth line and final line is the standard way of telling Rails to use the database for storing session. Regards, Ed -- Transmogrify, LLC * <http://xmog.com>
Brad- There is definitely some inconsistency with the script/generate scaffold command. The way it works that is confusing is that if you just give it one controller to generate like this: $ script/generate scaffold Post It will make your controller called posts_controller.rb which does not make much sense. But if you do it like this: $ script/generate scaffold post Post It will generate the controller as post_controller.rb(singular) and a post.rb model. So you need to specify both controller and model in one command for it to work like expected. I''m not sure why it behaves the way it does but this is the workaround that I use. HTH- -Ezra Zygmuntowicz Yakima Herald-Republic WebMaster 509-577-7732 ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org On Aug 8, 2005, at 5:48 AM, Ed Watkeys wrote:> Brad, > > You can specify two arguments when generating a scaffold: > > script/generate scaffold <model> <controller> > > Check out the new movie on rubyonrails.com. In there the following is > typed IIRC: > > script/generate scaffold Post Blog > > A blog is made up of posts. I agree with you that the pluralizing > behavior > is stupid. I think /item/list, /item/create, and /item/show/12 make > more > sense and are shorter than /items/list, /items/create, and /items/ > show/12. > I''ll usually add a route to map /items to /item/list. > > Of course, take my comments with a grain of salt, because I think > Rails''s > default convention of using plural database table names is profoundly > wrong. The class from which we instantiate people is not called > People, > it''s called Person, but people seem to get locked into thinking > about the > many rows of data in a table, not the logical entity that the table > represents. > > Regards, > Ed > > -- > Transmogrify, LLC * <http://xmog.com> > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Julian Leviston said:> Why not just turn pluralisation off in the settings?In the settings for what, script/generate? I didn''t know that had such a setting. If you''re referring to AR, then read on, I addressed that in a more recent message. Regards, Ed -- Transmogrify, LLC * <http://xmog.com>