Hi, For some reason I can''t get the following class to work, here is the setup. 1. I have the following method in the controller def suggestions @suggestion = Suggestion.new("Jonny Doe", "Developer") render :text => @suggestion.name end 2. Here is the class class Suggestion def initialize(name,profession) @name=name @profession = profession end def name @name end end 3. When I go to the suggestions action I get the following error: ArgumentError in Shahablab#suggestions wrong number of arguments (2 for 1) RAILS_ROOT: ./script/../config/.. Application <http://dreamer:3001/shahablab/suggestions> Trace | Framework Trace <http://dreamer:3001/shahablab/suggestions> | Full Trace <http://dreamer:3001/shahablab/suggestions> #{RAILS_ROOT}/app/controllers/shahablab_controller.rb:60:in `initialize'' #{RAILS_ROOT}/app/controllers/shahablab_controller.rb:60:in `new'' #{RAILS_ROOT}/app/controllers/shahablab_controller.rb:60:in `suggestions'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 834:in `send'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 834:in `perform_action_without_filters'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/filters. rb:295:in `perform_action_without_benchmark'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmar king.rb:69:in `perform_action_without_rescue'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmar king.rb:69:in `measure'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmar king.rb:69:in `perform_action_without_rescue'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/rescue.r b:82:in `perform_action'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 365:in `send'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 365:in `process_without_session_management_support'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/session_ management.rb:116:in `process'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/dispatcher.rb:36:in `dispatch'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:117:in `handle_dispatch'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:83: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:155:in `start_thread'' /usr/lib/ruby/1.8/webrick/server.rb:144:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'' /usr/lib/ruby/1.8/webrick/server.rb:94:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:89:in `each'' /usr/lib/ruby/1.8/webrick/server.rb:89:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:79:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:79:in `start'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:69:in `dispatch'' script/server:49 #{RAILS_ROOT}/app/controllers/shahablab_controller.rb:60:in `initialize'' #{RAILS_ROOT}/app/controllers/shahablab_controller.rb:60:in `new'' #{RAILS_ROOT}/app/controllers/shahablab_controller.rb:60:in `suggestions'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 834:in `send'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 834:in `perform_action_without_filters'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/filters. rb:295:in `perform_action_without_benchmark'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmar king.rb:69:in `perform_action_without_rescue'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmar king.rb:69:in `measure'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmar king.rb:69:in `perform_action_without_rescue'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/rescue.r b:82:in `perform_action'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 365:in `send'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 365:in `process_without_session_management_support'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/session_ management.rb:116:in `process'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/dispatcher.rb:36:in `dispatch'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:117:in `handle_dispatch'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:83: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:155:in `start_thread'' /usr/lib/ruby/1.8/webrick/server.rb:144:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'' /usr/lib/ruby/1.8/webrick/server.rb:94:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:89:in `each'' /usr/lib/ruby/1.8/webrick/server.rb:89:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:79:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:79:in `start'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:69:in `dispatch'' script/server:49 Request Parameters: None Show <http://dreamer:3001/shahablab/suggestions> session dump --- :last_page: about_us flash: !ruby/hash:ActionController::Flash::FlashHash {} Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} Any ideas about what I am doing wrong? I realize that I can use attr_accessor to get/set the name attribute but right now I would just like to get this working. Thanks! Farhan _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi, I sent the following e-mail in the morning but my subscription to the list didn''t get processed until now. I am not sure where I can see if someone has answered. Any help? Please forgive the extra spaces, I had to copy this from a web interface :-(. Thanks! Farhan Hi, For some reason I can''t get the following class to work, here is the setup. 1. I have the following method in the controller def suggestions @suggestion = Suggestion.new("Jonny Doe", "Developer") render :text => @suggestion.name end 2. Here is the class class Suggestion def initialize(name,profession) @name=name @profession = profession end def name @name end end 3. When I go to the suggestions action I get the following error: ArgumentError in Shahablab#suggestions wrong number of arguments (2 for 1) RAILS_ROOT: ./script/../config/.. Application Trace <http://dreamer:3001/shahablab/suggestions> | Framework <http://dreamer:3001/shahablab/suggestions> Trace | Full <http://dreamer:3001/shahablab/suggestions> Trace #{RAILS_ROOT}/app/controllers/shahablab_controller.rb:60:in `initialize'' #{RAILS_ROOT}/app/controllers/shahablab_controller.rb:60:in `new'' #{RAILS_ROOT}/app/controllers/shahablab_controller.rb:60:in `suggestions'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 834:in `send'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 834:in `perform_action_without_filters'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/filters. rb:295:in `perform_action_without_benchmark'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmar king.rb:69:in `perform_action_without_rescue'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmar king.rb:69:in `measure'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmar king.rb:69:in `perform_action_without_rescue'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/rescue.r b:82:in `perform_action'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 365:in `send'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 365:in `process_without_session_management_support'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/session_ management.rb:116:in `process'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/dispatcher.rb:36:in `dispatch'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:117:in `handle_dispatch'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:83: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:155:in `start_thread'' /usr/lib/ruby/1.8/webrick/server.rb:144:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'' /usr/lib/ruby/1.8/webrick/server.rb:94:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:89:in `each'' /usr/lib/ruby/1.8/webrick/server.rb:89:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:79:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:79:in `start'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:69:in `dispatch'' script/server:49 #{RAILS_ROOT}/app/controllers/shahablab_controller.rb:60:in `initialize'' #{RAILS_ROOT}/app/controllers/shahablab_controller.rb:60:in `new'' #{RAILS_ROOT}/app/controllers/shahablab_controller.rb:60:in `suggestions'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 834:in `send'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 834:in `perform_action_without_filters'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/filters. rb:295:in `perform_action_without_benchmark'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmar king.rb:69:in `perform_action_without_rescue'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmar king.rb:69:in `measure'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmar king.rb:69:in `perform_action_without_rescue'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/rescue.r b:82:in `perform_action'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 365:in `send'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb: 365:in `process_without_session_management_support'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/session_ management.rb:116:in `process'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/dispatcher.rb:36:in `dispatch'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:117:in `handle_dispatch'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:83: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:155:in `start_thread'' /usr/lib/ruby/1.8/webrick/server.rb:144:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'' /usr/lib/ruby/1.8/webrick/server.rb:94:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:89:in `each'' /usr/lib/ruby/1.8/webrick/server.rb:89:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:79:in `start'' /usr/lib/ruby/1.8/webrick/server.rb:79:in `start'' /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:69:in `dispatch'' script/server:49 Request Parameters: None Show session dump <http://dreamer:3001/shahablab/suggestions> --- :last_page: about_us flash: !ruby/hash:ActionController::Flash::FlashHash {} Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} Any ideas about what I am doing wrong? I realize that I can use attr_accessor to get/set the name attribute but right now I would just like to get this simple implementation working. Thanks! Farhan _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi, The problem is the initialize() definition. The framework expects a 3-argument version while you have defined a 2-arg version. I would suggest that you not use initialize at all and instead do initialization after constructing objects. On 11/1/05, Farhan Ahmad <fahmad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > For some reason I can''t get the following class to work, here is the > setup. > > > 1. I have the following method in the controller > > def suggestions > > @suggestion = Suggestion.new("Jonny Doe", "Developer") > > render :text => @suggestion.name <http://suggestion.name> > > end > > > 1. Here is the class > > class Suggestion > > def initialize(name,profession) > > @name=name > > @profession = profession > > end > > def name > > @name > > end > > end > > > 1. When I go to the suggestions action I get the following error: > > *ArgumentError in Shahablab#suggestions * > > wrong number of arguments (2 for 1) > > RAILS_ROOT: ./script/../config/.. > > Application Trace <http://dreamer:3001/shahablab/suggestions> | Framework > Trace <http://dreamer:3001/shahablab/suggestions> | Full Trace<http://dreamer:3001/shahablab/suggestions> > > *#{RAILS_ROOT}*/app/controllers/shahablab_controller.rb:60:in `initialize'' > > *#{RAILS_ROOT}*/app/controllers/shahablab_controller.rb:60:in `new'' > > *#{RAILS_ROOT}*/app/controllers/shahablab_controller.rb:60:in `suggestions'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb:834:in `send'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb:834:in `perform_action_without_filters'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/filters.rb:295:in `perform_action_without_benchmark'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmarking.rb:69:in `measure'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/rescue.rb:82:in `perform_action'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb:365:in `send'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb:365:in `process_without_session_management_support'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/session_management.rb:116:in `process'' > > /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/dispatcher.rb:36:in `dispatch'' > > /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:117:in `handle_dispatch'' > > /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:83: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:155:in `start_thread'' > > /usr/lib/ruby/1.8/webrick/server.rb:144:in `start'' > > /usr/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'' > > /usr/lib/ruby/1.8/webrick/server.rb:94:in `start'' > > /usr/lib/ruby/1.8/webrick/server.rb:89:in `each'' > > /usr/lib/ruby/1.8/webrick/server.rb:89:in `start'' > > /usr/lib/ruby/1.8/webrick/server.rb:79:in `start'' > > /usr/lib/ruby/1.8/webrick/server.rb:79:in `start'' > > /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:69:in `dispatch'' > > script/server:49 > > *#{RAILS_ROOT}*/app/controllers/shahablab_controller.rb:60:in `initialize'' > > *#{RAILS_ROOT}*/app/controllers/shahablab_controller.rb:60:in `new'' > > *#{RAILS_ROOT}*/app/controllers/shahablab_controller.rb:60:in `suggestions'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb:834:in `send'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb:834:in `perform_action_without_filters'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/filters.rb:295:in `perform_action_without_benchmark'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmarking.rb:69:in `measure'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/rescue.rb:82:in `perform_action'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb:365:in `send'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/base.rb:365:in `process_without_session_management_support'' > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_controller/session_management.rb:116:in `process'' > > /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/dispatcher.rb:36:in `dispatch'' > > /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:117:in `handle_dispatch'' > > /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:83: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:155:in `start_thread'' > > /usr/lib/ruby/1.8/webrick/server.rb:144:in `start'' > > /usr/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'' > > /usr/lib/ruby/1.8/webrick/server.rb:94:in `start'' > > /usr/lib/ruby/1.8/webrick/server.rb:89:in `each'' > > /usr/lib/ruby/1.8/webrick/server.rb:89:in `start'' > > /usr/lib/ruby/1.8/webrick/server.rb:79:in `start'' > > /usr/lib/ruby/1.8/webrick/server.rb:79:in `start'' > > /usr/lib/ruby/gems/1.8/gems/rails-0.14.2/lib/webrick_server.rb:69:in `dispatch'' > > script/server:49 > > *Request* > > *Parameters*: None > > Show session dump <http://dreamer:3001/shahablab/suggestions> > > --- > > :last_page: about_us > > flash: !ruby/hash:ActionController::Flash::FlashHash {} > > *Response* > > *Headers*: {"cookie"=>[], "Cache-Control"=>"no-cache"} > > Any ideas about what I am doing wrong? I realize that I can use > attr_accessor to get/set the name attribute but right now I would just like > to get this working. > > Thanks! > > Farhan > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails