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/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---