active admin render edit page
Asked Answered
Y

2

6

I can easily redirect but I'd like to do a render the edit page on validation failure so I carry over all the validation methods into the form. I'm not sure how to render the edit action using active_admin.

If I try render :action => 'edit' I get a template missing page I also tried render active_admin_template('edit.html.arb') which gives me a page within a page, but no errors.

Any ideas?

  member_action :state do
    space = Space.find(params[:id])
    if space.send(params[:state])
      #space.send(params[:state]+"!")
      flash[:notice] = "State Changed!"
      redirect_to :action => :index
    else
      #render :action => 'edit'
      #render active_admin_template('edit.html.arb')
      flash[:error] = "#{space.errors}"
      redirect_to :action => :edit
    end
  end
Yorke answered 25/10, 2011 at 11:29 Comment(0)
S
5

Have you tried this?

render active_admin_template('edit.html.arb'), :layout => false
Strive answered 26/10, 2011 at 20:15 Comment(3)
That solves the layout nesting problem, but is there anyway for it to highlight the fields that fail validation? In the normal way edit would? Currently I'm passing them in a flash method: "{:photos=>["does not have enough entries"], :blurb=>["Your message must be at least 50 words."]}"Yorke
Not sure, sorry. But I will probably need to solve this for my current project, too.Basilius
this method does not exist in more recent versions - see #6653593 for an alternative solutionSolicitor
O
3

I had a similar issue, but I was overriding the create controller and wanted all the active admin godness for rendering error messaegs. So here is what I did

controller do
 layout 'active_admin',  :only => [:create,:my_collection_method,:my_member_method]

 def create
 //my code here
 end
end

So basically, i added the 'layout "active_admin" ' line in my controller part and added ALL my custom methods. So the 'my_collection_method' is a custom collection action in the active amdin resource, something like

:my_collection_action, :method=>:get do
//my code here
end

You could try something similar

Over answered 30/7, 2012 at 11:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.