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.