Skip to content

Instantly share code, notes, and snippets.

@TiuTalk
Created July 30, 2013 13:42
Show Gist options
  • Save TiuTalk/6113017 to your computer and use it in GitHub Desktop.
Save TiuTalk/6113017 to your computer and use it in GitHub Desktop.
# admin/posts/_form.html.haml
= f.actions do
= f.action :submit, button_html: { onclick: 'this.form.target = "_self"; return true' }
= f.action :submit, label: 'Preview', button_html: { onclick: 'this.form.target = "_blank"; return true' }
# admin/posts.rb
# encoding: utf-8
ActiveAdmin.register Post do
controller do
def create
create! do |format|
format.html { redirect_to preview_or_back }
end
end
def update
update! do |format|
format.html { redirect_to preview_or_back }
end
end
private
def preview_or_back
if params[:commit] == 'Preview'
post_path(@post)
else
:back
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment