Hi, I was trying out the Authenticate HowTo example in rails and I encounter this wierd error. Upon clicking login form, actionController throws this error: Table ''weblog.people'' doesn''t exist: SELECT * FROM people WHERE name '''' AND password = '''' LIMIT 1 /app/models/person.rb:5:in `authenticate'' /app/controllers/login_controller.rb:9:in `authenticate'' however, my model (and table name) is called Person. Where did the ''people'' table comes from? I don''t find it in the controller code (copied exactly from the howto) <excerpt> def authenticate if @session["person"] = Person.authenticate(@params["name"], @params["password"]) .... </excerpt> thx in advance
Eric Anderson
2005-Jan-08 04:34 UTC
Re: Wierd ActiveRecord Error - different table name shown
boonhoo wrote:> however, my model (and table name) is called Person. Where did the > ''people'' table comes from? I don''t find it in the controller code > (copied exactly from the howto)Rails automatically pluralizes model names when looking for tables. This makes sense because you have many (plural) records in a table. :) If you want to change the default behavior you will need to put the following in your environment.rb file: ActiveRecord::Base.pluralize_table_names = false NOTE: this will change it for all models. Eric _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Jarkko Laine
2005-Jan-08 06:33 UTC
Re: Re: Wierd ActiveRecord Error - different table name shown
On 8.1.2005, at 06:34, Eric Anderson wrote:> boonhoo wrote: >> however, my model (and table name) is called Person. Where did the >> ''people'' table comes from? I don''t find it in the controller code >> (copied exactly from the howto) > > Rails automatically pluralizes model names when looking for tables. > This makes sense because you have many (plural) records in a table. :) > If you want to change the default behavior you will need to put the > following in your environment.rb file: > > ActiveRecord::Base.pluralize_table_names = falseYou can also override the table name in each model definition: class Mouse < ActiveRecord::Base def self.table_name() "mice" end end //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
boonhoo
2005-Jan-08 15:53 UTC
Re: Re: Wierd ActiveRecord Error - different table name shown
OIC, thanks for the pointer. I thought the plural form would be ''persons''...i didn''t know it will be that gramatically smart:o On Fri, 07 Jan 2005 23:34:26 -0500, Eric Anderson <eric-ANzg6odk14w@public.gmane.org> wrote:> boonhoo wrote: > > however, my model (and table name) is called Person. Where did the > > ''people'' table comes from? I don''t find it in the controller code > > (copied exactly from the howto) > > Rails automatically pluralizes model names when looking for tables. This > makes sense because you have many (plural) records in a table. :) If you > want to change the default behavior you will need to put the following > in your environment.rb file: > > ActiveRecord::Base.pluralize_table_names = false > > NOTE: this will change it for all models. > > Eric > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >
Eric Anderson
2005-Jan-08 19:06 UTC
Re: Wierd ActiveRecord Error - different table name shown
boonhoo wrote:> OIC, thanks for the pointer. I thought the plural form would be > ''persons''...i didn''t know it will be that gramatically smart:oCheck out activerecord/lib/active_record/support/inflector.rb for the conversion rules. Look towards the bottom for the rules to convert between singular and plural. It''s a good place to know if you ever get a situation where it is not pluralizing correctly. :) Eric _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails