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

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.
7d49e6bc317a9cd10b9b6cd6c56de067?d=identicon&s=25 EduardoChinchilla (Guest)
on 2009-03-05 15:35
(Received via mailing list)
Hi folks:

In my create action I´m getting this messagge:

ArgumentError (wrong number of arguments (1 for 0)):

What does this means? Do i´m passing more or less parameters than
needed?
Any guidance would be very appreciated

I´m using a form with 3 models, including a model to attach images
with Paperclip

The create action is pretty standard:

def create
@property = Property.new (:property)
end

These are the parameter:

Processing PropertiesController#create (for 127.0.0.1 at 2009-03-05
00:06:10) [POST]
  Parameters: {"commit"=>"Incluir Propiedad", "property"=>
{"garage"=>"1", "purpose"=>"Venta", "front"=>"25",
"rent_price"=>"1300", "baths"=>"1", "contact"=>{"company"=>"La cantera
del señor Rajuela", "cell"=>"0123456789", "phone"=>"0123456789",
"contact_type"=>"Propietario", "fax"=>"2255-14510",
"first_name"=>"Pedro", "last_name"=>"Picapiedra",
"email"=>"ppicapiedra@piedradura.com"}, "image_attributes"=>
[{"photo"=>""}, {"photo"=>""}, {"photo"=>""}, {"photo"=>""},
{"photo"=>""}, {"photo"=>""}, {"photo"=>""}], "this_type"=>"House",
"description"=>"casa grande", "rooms"=>"1", "localization"=>"en las
afueras", "exclusive"=>"0", "address"=>"100 norte del sur",
"lot_area"=>"1800", "const_area"=>"500", "province"=>"San Jose",
"sell_price"=>"500000",
"min_price"=>"150000"},"authenticity_token"=>"225a4b100cfce5efa6781ab2eabddc8b2d9690c7"}
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-05 16:00
(Received via mailing list)
On 5 Mar 2009, at 14:31, EduardoChinchilla wrote:

>
> I´m using a form with 3 models, including a model to attach images
> with Paperclip
>
> The create action is pretty standard:
>
> def create
> @property = Property.new (:property)
> end
>
I suspect the line raising that is somewhere inside active record.
Assuming Property is an ActiveRecord method it's expecting a hash to
be passed ( eg params[:property] ) but you're just passing the symbol
property.

Fred
7d49e6bc317a9cd10b9b6cd6c56de067?d=identicon&s=25 EduardoChinchilla (Guest)
on 2009-03-05 17:52
(Received via mailing list)
Thanks Frederick:

Sorry I mistyped the method definition, the correct is:

def create
@property = Property.new (params[:property])
end

Given that I had the error mentioned.

Any thoughts?


On Mar 5, 8:59 am, Frederick Cheung <frederick.che...@gmail.com>
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-05 18:49
(Received via mailing list)
On 5 Mar 2009, at 16:50, EduardoChinchilla wrote:

>
> Any thoughts?
Not without a stack trace (ruby should warn you that you should write
Property.new(params[:property]) but I don't think that would change
much).

Fred
7d49e6bc317a9cd10b9b6cd6c56de067?d=identicon&s=25 EduardoChinchilla (Guest)
on 2009-03-05 20:37
(Received via mailing list)
Thanks Frederick I really appreciate your continued support through
this list.

This is what I have:

ArgumentError (wrong number of arguments (1 for 0)):
    /app/controllers/properties_controller.rb:10:in `params'
    /app/controllers/properties_controller.rb:10:in `create'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
base.rb:1253:in `send'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
base.rb:1253:in `perform_action_without_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
filters.rb:617:in `call_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
filters.rb:610:in `perform_action_without_benchmark'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
benchmarking.rb:68:in `perform_action_without_rescue'
    /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
benchmarking.rb:68:in `perform_action_without_rescue'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
rescue.rb:136:in `perform_action_without_caching'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
caching/sql_cache.rb:13:in `perform_action'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/abstract/query_cache.rb:34:in `cache'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
query_cache.rb:8:in `cache'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
caching/sql_cache.rb:12:in `perform_action'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
base.rb:524:in `send'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
base.rb:524:in `process_without_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
filters.rb:606:in `process_without_session_management_support'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
session_management.rb:134:in `process'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
base.rb:392:in `process'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
dispatcher.rb:183:in `handle_request'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
dispatcher.rb:110:in `dispatch_unlocked'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
dispatcher.rb:123:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
dispatcher.rb:122:in `synchronize'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
dispatcher.rb:122:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
dispatcher.rb:132:in `dispatch_cgi'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
dispatcher.rb:39:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/webrick_server.rb:
103:in `handle_dispatch'
    /usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/webrick_server.rb:
74:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
    /usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/webrick_server.rb:
60:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/commands/servers/
webrick.rb:66
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/
dependencies.rb:153:in `require'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/
dependencies.rb:521:in `new_constants_in'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/
dependencies.rb:153:in `require'
    /usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/commands/server.rb:49
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
    script/server:3

Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_controller/templates/rescues/_trace (98.5ms)
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_controller/templates/rescues/_request_and_response (1.9ms)
Rendering /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_controller/templates/rescues/layout.erb (internal_server_error)


On Mar 5, 11:48 am, Frederick Cheung <frederick.che...@gmail.com>
666257c0d92ec15d69ae0e865277d21d?d=identicon&s=25 khiltd (Guest)
on 2009-03-05 20:52
(Received via mailing list)
Did you pick a method name that Rails is already using by any chance?
7d49e6bc317a9cd10b9b6cd6c56de067?d=identicon&s=25 EduardoChinchilla (Guest)
on 2009-03-05 22:45
(Received via mailing list)
khiltd:

Well I think that´s a possibility, but how could I check that?
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-05 22:49
(Received via mailing list)
On 5 Mar 2009, at 19:36, EduardoChinchilla wrote:

>
> Thanks Frederick I really appreciate your continued support through
> this list.
>
That to me looks like your code actually reads params(:property)
rather than params[:property]

Fred
7d49e6bc317a9cd10b9b6cd6c56de067?d=identicon&s=25 EduardoChinchilla (Guest)
on 2009-03-07 06:16
(Received via mailing list)
Ok. Solved
The problem was that I put a white space between params and the
brackets as: params [:property] instead of params[:property].
Thanks Fred and khiltd.
This topic is locked and can not be replied to.