Is it my environment? Is something wrong, cause I thought this should just work? I have a simple table and I created a model and a controller: ruby script/generate controller Restaurant ruby script/generate model Restaurant I edited the controller to this: class RestaurantController < ApplicationController scaffold :Restaurant end I run it and: http://0.0.0.0:3000/Restaurant works fine, gives me a list of restaurants. If I click on edit though I get this: Showing usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/templates/scaffolds/edit.rhtml where line #4 raised: wrong number of arguments (0 for 1) Extracted source (around line #4): 1: <h1>Editing <%= @scaffold_singular_name %></h1> 2: 3: <%= error_messages_for(@scaffold_singular_name) %> 4: <%= form(@scaffold_singular_name, :action => "update#{@scaffold_suffix}") %> 5: 6: <%= link_to "Show", :action => "show#{@scaffold_suffix}", :id => instance_variable_get("@#{@scaffold_singular_name}") %> | 7: <%= link_to "Back", :action => "list#{@scaffold_suffix}" %> Likewise if I click on New: ArgumentError in Restaurant#new Showing usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/templates/scaffolds/new.rhtml where line #4 raised: wrong number of arguments (0 for 1) Extracted source (around line #4): 1: <h1>New <%= @scaffold_singular_name %></h1> 2: 3: <%= error_messages_for(@scaffold_singular_name) %> 4: <%= form(@scaffold_singular_name, :action => "create#{@scaffold_suffix}") %> 5: 6: <%= link_to "Back", :action => "list#{@scaffold_suffix}" %> Here''s my table definition; CREATE TABLE `restaurants` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `name` VARCHAR(100) NOT NULL DEFAULT '''', `phone` VARCHAR(14) NOT NULL DEFAULT '''', `fax` VARCHAR(14) NOT NULL DEFAULT '''', `email` VARCHAR(100) DEFAULT '''', `web` VARCHAR(100) DEFAULT '''', `address1` VARCHAR(100) NOT NULL DEFAULT '''', `address2` VARCHAR(100) DEFAULT '''', `city` VARCHAR(100) NOT NULL DEFAULT '''', `state` CHAR(2) NOT NULL DEFAULT '''', `zip` VARCHAR(10) NOT NULL DEFAULT '''', `open` BOOLEAN NOT NULL DEFAULT 0, PRIMARY KEY(`id`) ) ENGINE = InnoDB CHARACTER SET utf8; This on Mac OSX. I set up Ruby and Rails accoring to this: http://hivelogic.com/articles/2005/12/01/ruby_rails_lighttpd_mysql_tiger -- Posted via http://www.ruby-forum.com/.
You want scaffold :restaurant note lowercase ''r'' http://api.rubyonrails.com/classes/ActionController/Scaffolding/ClassMethods.html#M000137 for the complete documentation and example. -- View this message in context: http://www.nabble.com/Help%3A-wrong-number-of-arguments-%280-for-1%29-t1554096.html#a4222485 Sent from the RubyOnRails Users forum at Nabble.com.
Thanks Steve I have tried both upper an lower case ''r'' and the behaviour is the same regardless. Any other suggestions? Steve Ross wrote:> You want > > scaffold :restaurant > > note lowercase ''r'' > > http://api.rubyonrails.com/classes/ActionController/Scaffolding/ClassMethods.html#M000137 > > for the complete documentation and example. > -- > View this message in context: > http://www.nabble.com/Help%3A-wrong-number-of-arguments-%280-for-1%29-t1554096.html#a4222485 > Sent from the RubyOnRails Users forum at Nabble.com.-- Posted via http://www.ruby-forum.com/.
Typically, I use singular for models and plural for controllers, but I''m not sure that''s it. You could give it a try by: script/destroy controller Restaurant script/create controller Restaurants This is just a guess, though. -- View this message in context: http://www.nabble.com/Help%3A-wrong-number-of-arguments-%280-for-1%29-t1554096.html#a4223445 Sent from the RubyOnRails Users forum at Nabble.com.
The error is telling you that you have supplied too many arguments to the form method. See the following on using the form method: http://api.rubyonrails.org/classes/ActionView/Helpers/ActiveRecordHelper.html#M000458 I think from you code that you only need to name the action and not the @scaffold stuff in the hash. Rails should already know what controller you are trying to access intuitively, but it looks like you are trying to tell it what controller in the :action argument...you could also try: :controller => @scaffold_whatever, :action => ''create'' Just taking a stab ;) Cheers, David -- Posted via http://www.ruby-forum.com/.
Yes, I guessed that is what it is complaining about. I guess my real question is, since I have NO custom code whatsoever other than the one scaffold line in the controller is why doesn''t this work? The code is generated by ROR as a result of the scaffold line. Is it generating bad code? This is after all the first step in every Ruby on Rails tutorial out there and it''s only parially working for me (list, show ok, edit, new not). I have tried various combinations on upper case and singlular, plural to no avail. My rails experiment is coming of the tracks remarkably quickly :-( David Hughes wrote:> The error is telling you that you have supplied too many arguments to > the form method. See the following on using the form method: > > http://api.rubyonrails.org/classes/ActionView/Helpers/ActiveRecordHelper.html#M000458 > > I think from you code that you only need to name the action and not the > @scaffold stuff in the hash. Rails should already know what controller > you are trying to access intuitively, but it looks like you are trying > to tell it what controller in the :action argument...you could also try: > > :controller => @scaffold_whatever, :action => ''create'' > > Just taking a stab ;) > > Cheers, > David-- Posted via http://www.ruby-forum.com/.
Donald Brady wrote:> Yes, I guessed that is what it is complaining about. I guess my real > question is, since I have NO custom code whatsoever other than the one > scaffold line in the controller is why doesn''t this work? The code is > generated by ROR as a result of the scaffold line. Is it generating bad > code? > > This is after all the first step in every Ruby on Rails tutorial out > there and it''s only parially working for me (list, show ok, edit, new > not). I have tried various combinations on upper case and singlular, > plural to no avail. > > My rails experiment is coming of the tracks remarkably quickly :-(What''s the full stack trace? I can''t see how the ''wrong number of arguments'' exception can have been raised by the form() line, so I''m guessing it''s somewhere lower. I can''t think I''ve ever seen this before... -- Alex
Jon Gretar Borgthorsson
2006-May-05 12:15 UTC
[Rails] Help: wrong number of arguments (0 for 1)
You can not have a column called open in your database. The problem is that RoR creates a class with the database with all the columns as method names. And the class inherits ActionRecord. And open is a method that is neccesary for ActionRecord and you basically are trying to overwrite that. So when ActionRecord tries to open a connection to database all the sudden it finds that the open method has been changed. I had the same problem while trying to create a controller with an action called send. So rename your database column "open" into something like "is_open" A list of Reserved Words is findable here: http://wiki.rubyonrails.com/rails/pages/ReservedWords On 5/4/06, Donald Brady <dbrady010@mac.com> wrote:> Is it my environment? Is something wrong, cause I thought this should > just work? > > I have a simple table and I created a model and a controller: > > ruby script/generate controller Restaurant > ruby script/generate model Restaurant > > I edited the controller to this: > > class RestaurantController < ApplicationController > scaffold :Restaurant > end > > I run it and: > > http://0.0.0.0:3000/Restaurant works fine, gives me a list of > restaurants. > > If I click on edit though I get this: > > Showing > usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/templates/scaffolds/edit.rhtml > where line #4 raised: > > wrong number of arguments (0 for 1) > Extracted source (around line #4): > > 1: <h1>Editing <%= @scaffold_singular_name %></h1> > 2: > 3: <%= error_messages_for(@scaffold_singular_name) %> > 4: <%= form(@scaffold_singular_name, :action => > "update#{@scaffold_suffix}") %> > 5: > 6: <%= link_to "Show", :action => "show#{@scaffold_suffix}", :id => > instance_variable_get("@#{@scaffold_singular_name}") %> | > 7: <%= link_to "Back", :action => "list#{@scaffold_suffix}" %> > > Likewise if I click on New: > > ArgumentError in Restaurant#new > > Showing > usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/templates/scaffolds/new.rhtml > where line #4 raised: > > wrong number of arguments (0 for 1) > Extracted source (around line #4): > > 1: <h1>New <%= @scaffold_singular_name %></h1> > 2: > 3: <%= error_messages_for(@scaffold_singular_name) %> > 4: <%= form(@scaffold_singular_name, :action => > "create#{@scaffold_suffix}") %> > 5: > 6: <%= link_to "Back", :action => "list#{@scaffold_suffix}" %> > > > Here''s my table definition; > > CREATE TABLE `restaurants` ( > `id` INTEGER NOT NULL AUTO_INCREMENT, > `name` VARCHAR(100) NOT NULL DEFAULT '''', > `phone` VARCHAR(14) NOT NULL DEFAULT '''', > `fax` VARCHAR(14) NOT NULL DEFAULT '''', > `email` VARCHAR(100) DEFAULT '''', > `web` VARCHAR(100) DEFAULT '''', > `address1` VARCHAR(100) NOT NULL DEFAULT '''', > `address2` VARCHAR(100) DEFAULT '''', > `city` VARCHAR(100) NOT NULL DEFAULT '''', > `state` CHAR(2) NOT NULL DEFAULT '''', > `zip` VARCHAR(10) NOT NULL DEFAULT '''', > `open` BOOLEAN NOT NULL DEFAULT 0, > PRIMARY KEY(`id`) > ) > ENGINE = InnoDB > CHARACTER SET utf8; > > This on Mac OSX. I set up Ruby and Rails accoring to this: > > http://hivelogic.com/articles/2005/12/01/ruby_rails_lighttpd_mysql_tiger > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- -------------- Jon Gretar Borgthorsson http://www.jongretar.net/
Ahhhhhhhh Thank you!! When your new error messages can be so inscrutable. J?n Borg??rsson wrote:> You can not have a column called open in your database. The problem is > that RoR creates a class with the database with all the columns as > method names. And the class inherits ActionRecord. And open is a > method that is neccesary for ActionRecord and you basically are trying > to overwrite that. So when ActionRecord tries to open a connection to > database all the sudden it finds that the open method has been > changed. > > I had the same problem while trying to create a controller with an > action called send. > > So rename your database column "open" into something like "is_open" > > A list of Reserved Words is findable here: > http://wiki.rubyonrails.com/rails/pages/ReservedWords > > On 5/4/06, Donald Brady <dbrady010@mac.com> wrote: >> class RestaurantController < ApplicationController >> Showing >> "update#{@scaffold_suffix}") %> >> usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/templates/scaffolds/new.rhtml >> 5: >> `email` VARCHAR(100) DEFAULT '''', >> CHARACTER SET utf8; >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > ---- Posted via http://www.ruby-forum.com/.
Jon Gretar Borgthorsson
2006-May-06 13:02 UTC
[Rails] Re: Help: wrong number of arguments (0 for 1)
Yeah. Technically this is a feature in Ruby. :) Allowing you to overwrite everything for if you need something different for this one thing. Problem is that you just have to remember a whole lot of things. On 5/5/06, Donald Brady <dbrady010@mac.com> wrote:> Ahhhhhhhh > > Thank you!! > > When your new error messages can be so inscrutable. > > > J?n Borg??rsson wrote: > > You can not have a column called open in your database. The problem is > > that RoR creates a class with the database with all the columns as > > method names. And the class inherits ActionRecord. And open is a > > method that is neccesary for ActionRecord and you basically are trying > > to overwrite that. So when ActionRecord tries to open a connection to > > database all the sudden it finds that the open method has been > > changed. > > > > I had the same problem while trying to create a controller with an > > action called send. > > > > So rename your database column "open" into something like "is_open" > > > > A list of Reserved Words is findable here: > > http://wiki.rubyonrails.com/rails/pages/ReservedWords > > > > On 5/4/06, Donald Brady <dbrady010@mac.com> wrote: > >> class RestaurantController < ApplicationController > >> Showing > >> "update#{@scaffold_suffix}") %> > >> usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/templates/scaffolds/new.rhtml > >> 5: > >> `email` VARCHAR(100) DEFAULT '''', > >> CHARACTER SET utf8; > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > > > > > -- > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- -------------- Jon Gretar Borgthorsson http://www.jongretar.net/