Rails: Active Admin Association Column

I'm new to Ruby on rails and just installed an active admin and tried to set up

points of view.

I have a table of products and images. Each image belongs to one product.

Now I want to display a column with a related image when showing the product page.

At the moment, this is just the text image_url, which does not work. Later i would do

50x50px image will be displayed.

How to do it? (image model: name: string image_url: text)

Here is what I did:

ActiveAdmin.register Product do index do column "Image" do |image| image.image_url end column :name column :preview_text column :full_text column :price, :sortable => :price do |product| div :class => "price" do number_to_currency product.price end end default_actions end end 

I don’t know how to fix this part using “make image”. I am a beginner in rails 2 days exp ..

The syntax seems to be wrong and the throwing error:

 undefined method `image_url' for #<Product:0x00000101b5a458> 

thanks

+7
source share
2 answers

You need to get image_url from the image object product.image.image_url .

Regarding the size of the image, you can display the image with the desired size, thus

 column "Image" do |product| image_tag product.image.image_url, class: 'my_image_size' end 

.css

 .my_image_size { width: 50px; height: 50px; } 

Or you can resize the image itself with a gem like CarrierWave .

+10
source
 column "Image" do |product| image_tag (product.image,width:100,height:80) end references image=it belongs to your database column name product=it creates new object for your image by activeadmin register class method. 
0
source

All Articles