ActiveAdmin - how to set up an edit action?

I have a code:

ActiveAdmin.register MyTable do controller

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 my edit template code under the heading to be: Http: // * / admin / tuBaE / 1 / edit BUT activeadmin does not see me my code / It shows the code with its own template, not mine Why?

+4
source share
2 answers

You must do this using the form DSL method provided by ActiveAdmin. See the documentation for ActiveAdmin and Formtastic for more information.

Unfortunately, I do not think that ActiveAdmin perfectly allows you to have a completely different form for new and edit . Using the partial rendering method in the documentation, although you can 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 %> 
+7
source

You can display any view, for example, if you provide the full path to the rendering 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 
0
source

All Articles