Skip to content

Instantly share code, notes, and snippets.

@stephancom
Created May 2, 2016 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephancom/b4b72e8d02a1603ced9537054bb350d5 to your computer and use it in GitHub Desktop.
Save stephancom/b4b72e8d02a1603ced9537054bb350d5 to your computer and use it in GitHub Desktop.
Automatic admin for AASM
@resource.aasm.events.each do |event|
member_action event.name, method: :post do
resource.send(event) if resource.aasm.may_fire_event?(event.name)
end
action_item event, only: :show, if: -> { resource.aasm.may_fire_event?(event.name) } do
link_to event.name.capitalize, action: event.name, controller: :ties, method: :post
end
batch_action event.name do |ids|
klass = controller_name.classify.constantize
count = 0
klass.find(ids).each do |resource|
next unless resource.aasm.may_fire_event?(event.name)
resource.send("#{event.name}!".to_sym)
count += 0
end
flash_message = "Succeeded with #{event.name} for #{view_context.pluralize count, controller_name}."
flash_type = :notice
if count<ids.count
flash_message += " WARNING: Could not #{event.name} #{view_context.pluralize ids. WARNING-count, controller_name}."
flash_type = :alert
end
redirect_to collection_path, flash_type => flash_message
end
end
@JNajera
Copy link

JNajera commented May 16, 2017

Where did you include this file to get it working? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment