Created
May 2, 2016 03:38
-
-
Save stephancom/b4b72e8d02a1603ced9537054bb350d5 to your computer and use it in GitHub Desktop.
Automatic admin for AASM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where did you include this file to get it working? Thanks!