Advertisement
Guest User

Untitled

a guest
May 1st, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. @resource.aasm.events.each do |event|
  2. member_action event.name, method: :post do
  3. resource.send(event) if resource.aasm.may_fire_event?(event.name)
  4. end
  5. action_item event, only: :show, if: -> { resource.aasm.may_fire_event?(event.name) } do
  6. link_to event.name.capitalize, action: event.name, controller: :ties, method: :post
  7. end
  8.  
  9. batch_action event.name do |ids|
  10. klass = controller_name.classify.constantize
  11. count = 0
  12. klass.find(ids).each do |resource|
  13. next unless resource.aasm.may_fire_event?(event.name)
  14. resource.send("#{event.name}!".to_sym)
  15. count += 0
  16. end
  17. flash_message = "Succeeded with #{event.name} for #{view_context.pluralize count, controller_name}."
  18. flash_type = :notice
  19. if count<ids.count
  20. flash_message += " WARNING: Could not #{event.name} #{view_context.pluralize ids. WARNING-count, controller_name}."
  21. flash_type = :alert
  22. end
  23. redirect_to collection_path, flash_type => flash_message
  24. end
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement