1
votes

I'm new ruby and ruby on rails. I want image upload with active admin
I follow this code
app\admin\book.rb ActiveAdmin.register Book do

# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
 permit_params :list, :of, :attributes, :on, :model
#
# or
#
# permit_params do
#   permitted = [:permitted, :attributes]
#   permitted << :other if resource.something?
#   permitted
# end
index do
  column :name
  column :image


  column :author
  column :genre
  column :price
  actions
end
form :html => { :enctype => "multipart/form-data" } do |f|
   f.inputs "Details" do
    f.input :image, :as => :file, :hint => f.template.image_tag(f.object.image.url(:medium))
    f.input :author
    f.input :name
  end
  f.actions
 end
end

And
app\models\book.rb

class Book < ActiveRecord::Base
  belongs_to :author
  belongs_to :genre
has_attached_file :image, :styles => { :medium => "238x238>", 
                                   :thumb => "100x100>"
                                 }
end

Yes i see file upload button in create page. But don't save form.

1
I couldn't understand your question. Can you re-phrase your question? - Rubyrider
I did, book crud, author crud and genres crud with active admin. I want add book image for my books. I can do this with rails but i want to use active admin. Sorry for my English. Did you understand me? Thank you. - balkondemiri
is that what you meant, you can't save your record in active admin right? but you can do this outside of active admin? - Rubyrider
Yes, My record is don't save - balkondemiri

1 Answers

0
votes

You should add your parameters to permitted parameters list.

#
# I can assume these are your fields that is 
# what you will submit with your form. 
# Try replacing my code with yours. 
# That will work if you don't make other changes.
#
permit_params :image, :author, :name

Let me know how it goes. Share your log if you face any error, I will update my answer if needed.