Forum: Ruby on Rails Help: wrong number of arguments (0 for 1)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
026b6055c4c2a996a77ec04ebd8133e3?d=identicon&s=25 Donald Brady (dbrady010)
on 2006-05-04 05:01
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_rail...
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2006-05-04 05:34
(Received via mailing list)
You want

scaffold :restaurant

note lowercase 'r'

http://api.rubyonrails.com/classes/ActionControlle...

for the complete documentation and example.
--
View this message in context:
http://www.nabble.com/Help%3A-wrong-number-of-argu...
Sent from the RubyOnRails Users forum at Nabble.com.
026b6055c4c2a996a77ec04ebd8133e3?d=identicon&s=25 Donald Brady (dbrady010)
on 2006-05-04 07:04
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/ActionControlle...
>
> for the complete documentation and example.
> --
> View this message in context:
> 
http://www.nabble.com/Help%3A-wrong-number-of-argu...
> Sent from the RubyOnRails Users forum at Nabble.com.
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2006-05-04 07:51
(Received via mailing list)
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-argu...
Sent from the RubyOnRails Users forum at Nabble.com.
Fa06489a97b0efe3c3b7d249982878d3?d=identicon&s=25 David Hughes (divotdave)
on 2006-05-04 08:26
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/Help...

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
026b6055c4c2a996a77ec04ebd8133e3?d=identicon&s=25 Donald Brady (dbrady010)
on 2006-05-04 17:53
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/Help...
>
> 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
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-05-05 10:07
(Received via mailing list)
Donald Brady wrote:
>
> 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...
30ee518e6fdc5b07e060775b5a542bdb?d=identicon&s=25 Jón Borgþórsson (jongretar)
on 2006-05-05 14:17
(Received via mailing list)
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
>


--
026b6055c4c2a996a77ec04ebd8133e3?d=identicon&s=25 Donald Brady (dbrady010)
on 2006-05-05 23:30
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
>>
>
>
> --
30ee518e6fdc5b07e060775b5a542bdb?d=identicon&s=25 Jón Borgþórsson (jongretar)
on 2006-05-06 15:05
(Received via mailing list)
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:
> > method names. And the class inherits ActionRecord. And open is a
> > A list of Reserved Words is findable here:
> >> http://lists.rubyonrails.org/mailman/listinfo/rails
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
This topic is locked and can not be replied to.