4

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?

user1942979
  • 119
  • 1
  • 2
  • 6

2 Answers2

8

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 %>
joshhepworth
  • 2,976
  • 1
  • 16
  • 18
2

You can render any view your like if you provide its full path to the render method. Something like that:

# app/admin/post.rb 
ActiveAdmin.register Post do  
    controller do
        def edit 
            render 'admin/posts/myEditTemplate', :layout =>"active_admin"
        end
        def new
            render 'admin/posts/myNewTemplate', :layout =>"active_admin"
        end
    end
end 

# app/views/admin/posts/myEditTemplate.html.erb
    # Your erb view for edit here
# app/views/admin/posts/myNewTemplate.html.erb
    # Your erb view for new here
Alex Piriz
  • 36
  • 5