Hi, I am using Rails 0.13.1. To handle special plurals (here the french "pays" invariable), I added the word ''pays'' to the method uncountable_words from the module Inflector. It seems to work. I wonder if there is a way to add rules to the module Inflector without modifying the file inflector.rb, like overloading or overriding a method (I am new to the Ruby language)? Congratulations to the developpers: great framework and great language! Mathias Breuninger
Please, please, please, I''m new to Rails, trying to study it and build some simple applications. But I''m not able to do anything. I traced the errors and it seems that the great source of all problems I have is the pluras mechanism. It just rename things under my hands without a notice so nothing works and all table/class names are wrong. Please, pleas, please, is there a way to completly shoot down this autorenaming feature? My last problem is: I have table ''pokus''. Using http://wiki.rubyonrails.com/rails/show/HowToUseLegacySchemas I wrote/rewrote model to: File: app/models/pokus.rb class Pokus < ActiveRecord::Base def self.table_name() ''pokus'' end end ---EOF And the controller in file app/controllers/pokus_controller.rb to: class PokusController < ApplicationController model :pokus scaffold :pokus end ---EOF and the application displays error NameError in Pokus#index uninitialized constant Poku I can''t find where and how to map all the things than Rails maps behaind the scene with autorenaming. -- Radek Hnilica <Radek at Hnilica dot CZ> http://www.hnilica.cz
Radek Hnilica wrote:>Please, pleas, please, is there a way to completly shoot down this >autorenaming feature? > > >http://wiki.rubyonrails.com/rails/show/HowtoDisableAutoTableNamePluralisation In short, add the line: |ActiveRecord::Base.pluralize_table_names = false | to the bottom of: |rails_application_path/config/environment.rb | -- R.Livsey http://livsey.org
On Tue, Jul 19, 2005 at 11:52:11AM +0100, Richard Livsey wrote:> Radek Hnilica wrote: > > >Please, pleas, please, is there a way to completly shoot down this > >autorenaming feature? > > > > > > > http://wiki.rubyonrails.com/rails/show/HowtoDisableAutoTableNamePluralisation > > In short, add the line: > > |ActiveRecord::Base.pluralize_table_names = false > | > > to the bottom of: > > |rails_application_path/config/environment.rb > | >:( It does not help. I write the line on the end of the file and also in the middle of the file. Restart server. But the error is the same: NameError in Pokus#index uninitialized constant Poku script/server:49 /usr/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/dependencies.rb:186:in `const_missing'' /usr/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/core_ext/string/../../inflector.rb:59:in `const_get'' /usr/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/core_ext/string/../../inflector.rb:59:in `constantize'' /usr/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/core_ext/string/../../inflector.rb:58:in `inject'' /usr/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/core_ext/string/../../inflector.rb:58:in `each'' /usr/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/core_ext/string/../../inflector.rb:58:in `inject'' /usr/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/core_ext/string/../../inflector.rb:58:in `constantize'' /usr/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/core_ext/string/inflections.rb:44:in `constantize'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/pagination.rb:169:in `paginator_and_collection_for'' ... This error occured while loading the following files: poku.rb -- Radek Hnilica <Radek at Hnilica dot CZ> http://www.hnilica.cz
On Tue, Jul 19, 2005 at 01:34:34PM +0200, Radek Hnilica wrote:> > :( It does not help. I write the line on the end of the file and also > in the middle of the file. Restart server. But the error is the > same: >I still hope that putting somewhere code like # Kill Inflector module Inflector def pluralize(word) word end def singularize(word) word end end helps, but I do not know where to put that code. -- Radek Hnilica <Radek at Hnilica dot CZ> http://www.hnilica.cz
scaffold takes the class name as well... that should take care of your problem... _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Tue, Jul 19, 2005 at 12:32:03PM -0400, Sean T Allen wrote:> scaffold takes the class name as well...I think it''s not true. Scafold takes some unknown argument, do some black magic with it and then takes class name from that magic and oraculum. Try to prove. I''ll be happy If I''m wrong.> > that should take care of your problem...No. Try to test it by yourself. The black magic have to do something with Inflector. So if I''m able to kill that inflector, may be there will be a chance. The code is: class Pokus < ActiveRecord::Base set_table_name ''pokus'' end class PokusController < ApplicationController scaffold :pokus end Table name is ''pokus'' As its displayed on error page. The Rails strips the ending ''s'' from the class name and try to work with class Poku which does not exist. Imagine a databes with two tables: tabulkas and tabulka I think all those problems come from black magic with english plurals and singulars. -- Radek Hnilica <Radek at Hnilica dot CZ> http://www.hnilica.cz
Radek Hnilica wrote:>On Tue, Jul 19, 2005 at 12:32:03PM -0400, Sean T Allen wrote: > > >>scaffold takes the class name as well... >> >> > >I think it''s not true. > >Scafold takes some unknown argument, do some black magic with it and >then takes class name from that magic and oraculum. > >Try to prove. I''ll be happy If I''m wrong. > > >http://api.rubyonrails.com/classes/ActionController/Scaffolding/ClassMethods.html#M000107 scaffold(model_id, options = {}) Adds a swath of generic CRUD actions to the controller. The model_id is automatically converted into a class name unless one is specifically provide through options[:class_name]. So scaffold :post would use Post as the class and @post/@posts for the instance variables. It’s possible to use more than one scaffold in a single controller by specifying options[:suffix] = true. This will make scaffold :post, :suffix => true use method names like list_post, show_post, and create_post instead of just list, show, and post. If suffix is used, then no index method is added _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Tue, Jul 19, 2005 at 01:14:29PM -0400, Sean T Allen wrote:> http://api.rubyonrails.com/classes/ActionController/Scaffolding/ClassMethods.html#M000107 > > scaffold(model_id, options = {})...cut... I wrote following into controller: class PokusController < ApplicationController scaffold :pokus, :class_name => ''Pokus'' def seznam @pokus_pages, @pokusy = paginate :pokus, :per_page =>20, :class_name => ''Pokus'' end end What I''m doing wrong? Still do not work. The same error. uninitialized constant Poku This error occured while loading the following files: poku.rb the method seznam seems to be right. But scaffolding no. -- Radek Hnilica <Radek at Hnilica dot CZ> http://www.hnilica.cz
I think paginate is causing the problem. Not in seznam but the default generated scaffolding for say list... doesnt pass :class_name to paginate thus causing a problem. definately a ''bug''... override or generate the scaffolding out and avoid it altogether... or modify the default scaffolding... Radek Hnilica wrote:>On Tue, Jul 19, 2005 at 01:14:29PM -0400, Sean T Allen wrote: > > >>http://api.rubyonrails.com/classes/ActionController/Scaffolding/ClassMethods.html#M000107 >> >>scaffold(model_id, options = {}) >> >> > >...cut... > >I wrote following into controller: >class PokusController < ApplicationController > scaffold :pokus, :class_name => ''Pokus'' > def seznam > @pokus_pages, @pokusy = paginate :pokus, :per_page =>20, :class_name => ''Pokus'' > end >end > >What I''m doing wrong? Still do not work. The same error. >uninitialized constant Poku >This error occured while loading the following files: > poku.rb > >the method seznam seems to be right. But scaffolding no. > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Tue, Jul 19, 2005 at 02:05:37PM -0400, Sean T Allen wrote:> I think paginate is causing the problem. > > Not in seznam > > but the default generated scaffolding for say list... doesnt pass > :class_name to paginate > thus causing a problem. definately a ''bug''... > > override or generate the scaffolding out and avoid it altogether... > > or modify the default scaffolding...I''m so new to Rails that I do not know where and how to write own scaffolding. :(, I''m playing with Rails just about 2 days. Finaly I found a way how to kill the Inflector. Magic disapears, and all things automagicaly works including scaffolding. I put following code at the end of environment.rb. module Inflector def pluralize(word) word end def singularize(word) word end end Thanks for help. -- Podepsána, swojí Wlastní rukou, jejich przeweliká dobrotiwost a pán sítí jejich, jenz wládne nad pakety a smerowaci wsemi. Radek Hnilica <Radek.Hnilica at Moraviapress dot CZ> Radek Hnilica <Radek.Mobile at Moraviapress dot CZ> Radek Hnilica <Radek at Hnilica dot CZ> http://www.hnilica.cz =============================================================No matter how far down the wrong road you''ve gone, turn back. Turkish proverb ... so turn back ... Now!