D
D
Dmitry2016-10-24 12:34:48
Ruby on Rails
Dmitry, 2016-10-24 12:34:48

How to fix an error when uploading an image to the admin panel?

db

class CreateLastProjectSliders < ActiveRecord::Migration[5.0]
  def change
    create_table :last_project_sliders do |t|
      t.string :img_slider

      t.timestamps
    end
  end
end

admin
ActiveAdmin.register LastProjectSlider do
  permit_params :img_slider

  index do
    selectable_column
    id_column
    column (:img_slider){ |category| image_tag(category.image_url, style: 'width: 100px') }
    actions
  end


  filter :created_at

  form do |f|
    f.inputs 'Category details' do
      f.input :img_slider
    end
    f.actions
  end
end

model
class LastProjectSlider < ApplicationRecord
  mount_uploader :img_slider, ImageUploader
  validates :image, presence: true
end

When I click on the link where I need to add images, I get this error

undefined method `image_url' for #<LastProjectSlider:0x007f66e320f930>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-10-24
@railsdev

Problem solved!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question