I have created original method and trying to pass newly instantiated object to ERB file, but encountering NoMethodError in ERB file with the following error message. ------------------------------------------------------- NoMethodError in Products#lookup Showing app/views/products/lookup.html.erb where line #3 raised: You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] Extracted source (around line #3): 1: <h1>Add product</h1> 2: 3: <% form_for(@product) do |f| %> 4: <%= f.error_messages %> 5: 6: <p> ------------------------------------------------------- Source Code products_controller.rb ------------------------------------------------------- # GET /products/lookup # GET /products/lookup.xml def lookup result = Amazon::Ecs.item_lookup(params[:id]).first_item @product = AmazonProduct.new( result.get(''asin''), result.get(''itemattributes/manufacturer''), result.get(''title''), "", result.get(''detailpageurl''), "" ) end end ------------------------------------------------------- lookup.html.erb ------------------------------------------------------- <h1>Add product</h1> <% form_for(@product) do |f| %> <%= f.error_messages %> <p> <%= f.label :id %>: <%= @product.amazon_asin %><br /> ------------------------------------------------------- When viewing @product variable by running this flow in Aptana debug mode and stop it at erb source code, @product seems to have information and not nil (See attached). I was trying to copy standard rails controller/erb approach for other method, but it''s not working well for this. May I have any advice? Thank you. Attachments: http://www.ruby-forum.com/attachment/3980/Picture_3.png -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-Aug-27 16:57 UTC
Re: NoMethodError with unexpected nil object in ERB
On Aug 27, 5:32 pm, Ryoichiro Kamiya <rails-mailing-l...@andreas- s.net> wrote:> > When viewing @product variable by running this flow in Aptana debug mode > and stop it at erb source code, @product seems to have information and > not nil (See attached). I was trying to copy standard rails > controller/erb approach for other method, but it''s not working well for > this. May I have any advice? Thank you. >is an instance of AmazonProduct look enough like an ActiveRecord model that you can pass it to form_for like that ? Fred> Attachments:http://www.ruby-forum.com/attachment/3980/Picture_3.png > > -- > Posted viahttp://www.ruby-forum.com/.
Ryoichiro Kamiya
2009-Aug-29 14:37 UTC
Re: NoMethodError with unexpected nil object in ERB
Frederick Cheung wrote:> On Aug 27, 5:32�pm, Ryoichiro Kamiya <rails-mailing-l...@andreas- > s.net> wrote: >> >> When viewing @product variable by running this flow in Aptana debug mode >> and stop it at erb source code, @product seems to have information and >> not nil (See attached). I was trying to copy standard rails >> controller/erb approach for other method, but it''s not working well for >> this. May I have any advice? Thank you. >> > is an instance of AmazonProduct look enough like an ActiveRecord model > that you can pass it to form_for like that ? > > FredThe AmazonProduct is inheriting the Product class which has been scaffolded by rails. Is the class which inheriting the ActiveRecord model class also assumed ActiveRecord model class? Class AmazonProduct < Product -- Posted via http://www.ruby-forum.com/.