Skip to content

Instantly share code, notes, and snippets.

@passalini
Last active August 29, 2015 14:27
Show Gist options
  • Save passalini/1e6a7f356f3ad1b88173 to your computer and use it in GitHub Desktop.
Save passalini/1e6a7f356f3ad1b88173 to your computer and use it in GitHub Desktop.
RailsAdmin aasm
def change_state
object = Object.find(params[:object_id])
object.send(params[:event] + '!')
redirect_to params[:redirect_to]
end
edit do
configure :change_aasm_state do
pretty_value do
links = ""
object = bindings[:object]
view = bindings[:view]
events = object.aasm.events.map(&:name)
events.each do |event|
label = I18n.t event, scope: [:activerecord, :attributes, :object, :aasm_event]
links += view.link_to(label, view.main_app.object_change_state_path(object, event: event,
redirect_to: view.rails_admin.edit_path(model_name: :object, id: object.id)),
class: 'btn btn-default', method: :put)
end
links.html_safe
end
read_only true
end
fields :change_aasm_state
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment