Skip to content

Instantly share code, notes, and snippets.

@markmcdonald51
Created February 3, 2015 20:56
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 markmcdonald51/5feff60cd592f6063991 to your computer and use it in GitHub Desktop.
Save markmcdonald51/5feff60cd592f6063991 to your computer and use it in GitHub Desktop.
ActiveScaffoldStateMachine ... lib/as_aasm.rb
module ActiveScaffoldStateMachine
# add to controller
#config.action_links.member.add 'get_states', position: false
=begin
Then create a view called get_states.js.erb and put it in the view dir or
a common directory called active_scaffold_overrides which contains the following:
<%
events = @record.aasm.events.map(&:name)
links = events.map do |event|
link_to(event .to_s.titleize, state_change_google_search_result_path(@record,
{ event: event}), method: :put, remote: true)
end
%>
<%= display_dynamic_action_group active_scaffold_config.action_links[:get_states],
links, @record, :class => 'report_submenu' %>
=end
def get_states
@record = find_if_allowed(params[:id], :read)
end
def state_change
@record = find_if_allowed(params[:id], :update)
event_name = params[:event]
# call the event on AASM (state_machine)
event = "#{event_name}!".to_sym
# this will update the row in the database and the table.
process_action_link_action do |record|
if (@record.send(event))
flash[:info] = as_("Record Updated: #{@record.title} to: #{event_name}".to_sym)
else
flash[:error] = as_(:error)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment