NoMethodError with unexpected nil object in ERB

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:

Add product


2:
3: <% form_for(@product) do |f| %>
4: <%= f.error_messages %>
5:
6:

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

Add product

<% form_for(@product) do |f| %>
<%= f.error_messages %>


<%= f.label :id %>: <%= @product.amazon_asin %>

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.

On Aug 27, 5:32 pm, Ryoichiro K. <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

Frederick C. wrote:

On Aug 27, 5:32�pm, Ryoichiro K. <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

The 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