Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAdmin - how to customize edit action?

Tags:

activeadmin

I have code :

ActiveAdmin.register MyTable do controller do

def edit
  #---This code doesn't work
  render :template=>"myEditTemplate.html",:layout =>"active_admin"
end

def new
  #--code in this section works fine
  render :template=>"myNewTemplate.html",:layout =>"active_admin"
end

end

I want to see my edit template code under url like this: http://*/admin/mytable/1/edit BUT activeadmin doesn't see me my code/It shows code with own template not my Why?

like image 993
user1942979 Avatar asked Dec 27 '22 12:12

user1942979


1 Answers

You should be able to do this via the form DSL method provided by ActiveAdmin. More details are in the documentation for ActiveAdmin and Formtastic.

Unfortunately, I don't believe ActiveAdmin nicely lets you have a completely different form rendered for new and edit. Using the partial rendering method in the documentation though you could conditionally change the form in the view based on @object.persisted?.

# app/admin/post.rb
ActiveAdmin.register Post do
  form :partial => "form"
end

# app/views/admin/post/_form.html.erb
<%= semantic_form_for [:admin, @post] do |f| %>
  <% if @post.persisted? %>
    Edit Form (Maybe rendered via a partial)
    <%= f.inputs :title, :body %>
    <%= f.buttons :commit %>
  <% else %>
    New Form
  <% end %>
<% end %>
like image 194
joshhepworth Avatar answered May 20 '23 09:05

joshhepworth