I’m using ActiveAdmin, here is my show page:
show do |product|
attributes_table do
row :name
row :photos do
@photos = product.photos
@photos.each do |p|
image_tag(p.photo)
end
end
end
active_admin_comments
end
I get this error: undefined method name' for #<Array:>
it’s on this line:
@photos = product.photos
Why and how? I dont even have name in Photo.
UPDATE
When I’m selecting one photo—for example the first photo of the product—it works! Really weird.
UPDATE
It was only resetting the WEBRICK … but now i encounter a new problem.
My photo holds the url is photo:string and when i’m using the code above it prints:
[#<Photo id: 1, created_at: "2012-08-31 20:34:15", updated_at: "2012-08-31 20:34:15", photo: "innoMicro.jpg", product_id: 3>]
And not the url only..
UPDATE (WORKING SOLUTION!)
Here is my final and working code:
show do |product|
attributes_table do
row :name
row :description
product.photos.each do |p|
row :photo do
image_tag(p.photo, :height => '256', :width => '256')
end
end
end
active_admin_comments
end
The problem is that each photo has a new row.. can i keep them all in the same row?
On a first glance, 2 things don’t look nice:
@photos = product.photos. Why the@? It’s not like you need that instance variable anywhere else, and you might be inadvertently clashing with something that ActiveAdmin generated behind the curtains. So play it safe and just make it a local variable. Simplest way to do it: lose the@.image_tag(p.photo)should becomeimage_tag(p.photo.url).Correct these two and do tell us if it’s fixed and if not, what’s the new error.
Hope this helps.