I added ActiveAdmin to my application and successfully changed the index-method for my resource. Now when I click on 'new resource' it brings me to the new-method just fine, however, there's a button missing (paperclip) in order to allow the user to upload an image-attachment.
I can not find a way to edit the view, neither do I find a way to completely rewrite the new-method.
If you need any code by me I can paste everything here.
Thanks! // Check the very bottom of this post for the solution!
// This is how I tried it, but it's not working. The changes I applied to 'app/admin/entry.rb' for my index-method worked, but the 'new'-method just doesn't work at all.
app/admin/entry.rb:
ActiveAdmin.register Entry do
index do
column :id
column :description
column :created_at
column :image_content_type
column do |entry|
links = link_to "Edit", edit_admin_entry_path(entry)
links += " "
links += link_to "Delete", admin_entry_path(entry), :method => :delete, data: { confirm: "Are you sure?" }
links
end
end
def new
form_for @entry, :html => {:multipart => true} do |f|
f.label :description
f.text_area :description
f.file_field :image
end
f.submit 'Save'
end
end
Before I added ActiveAdmin I just added a scaffold for Entry and used it like this: entries_controller.rb:
def new
@entry = Entry.new
end
View (new.html.slim):
h1 New entry
== render 'form'
= link_to 'Back', entries_path
The rendered form (_form.html.slim):
= form_for @entry, :html => {:multipart => true} do |f|
- if @entry.errors.any?
#error_explanation
h2 = "#{pluralize(@entry.errors.count, "error")} prohibited this entry from being saved:"
ul
- @entry.errors.full_messages.each do |message|
li = message
.field
= f.label :description
= f.text_area :description
= f.file_field :image
.actions = f.submit 'Save'
Now, while this still works when heading to localhost:3000/entries/new it simply shows the default view for localhost:3000/admin/entries/new
If you got any help, that'd be highly appreciated! Is there any way to see the existing code that ActiveAdmin already uses somehow? I may change it to my needs by simply adding that one field I need.
// SOLUTION:
app/admin/resource.rb
ActiveAdmin.register Entry do
permit_params :image, :description
index do
column :id
column :description
column :created_at
column :image_file_name
column :image_content_type
column do |entry|
links = link_to "Edit", edit_admin_entry_path(entry)
links += " "
links += link_to "Delete", admin_entry_path(entry), :method => :delete, data: { confirm: "Are you sure?" }
links
end
end
form do |f|
f.inputs "New Entry" do
f.input :description
f.input :image
end
f.actions
end
end