Skip to content

Instantly share code, notes, and snippets.

View madzhuga's full-sized avatar

Maxim Madzhuga madzhuga

View GitHub Profile
module ApplicationHelper
def show_back_to_operation_button
current_operation && !@skip_current_operation_button
end
end
body
...
main[role="main"]
== render 'layouts/messages'
- if show_back_to_operation_button
.btn-group
/ And just add a button right to layout.
/ I know I need to add a helper for that - will do that shortly
= button_to "Back to #{current_operation.title}",
RailsWorkflow::Engine.routes.url_helpers.navigate_to_operations_path,
body
header
...
main[role="main"]
...
/ Checking if we have some active current operation
- if current_operation
.btn-group
/ And just add a button right to layout.
/ I know I need to add a helper for that - will do that shortly
RailsWorkflow::ProcessManager.start_process(
template.id,
{ user: self, url_path: 'current_operation_path', url_params: self }
)
class CollectUserDataTemplate < RailsWorkflow::OperationTemplate
def after_operation_create(new_operation)
new_operation.data[:new_key] = 'new_value'
# new_operation.process.operations
new_operation.title += " [#{new_operation.data[:user].email}]"
end
end
# app/views/operations/collect_user_data.html.erb
<% user = current_operation.data[:user] %>
<% if current_operation.present? %>
<h1><%= current_operation.title %></h1>
<% end %>
<h3>User</h3>
<p>Email: <%= user.email if user.email %></p>
class User < ApplicationRecord
...
after_create :start_newcomer_process
def start_newcomer_process
template = RailsWorkflow::ProcessTemplate.find_by_title('New User Process')
# we using current_operation_path to navigate to a new endpoint
# when user picks up operation
RailsWorkflow::ProcessManager.start_process(
# app/controllers/operations_controller.rb
class OperationsController < ApplicationController
def current
render current_operation.tag
end
end
Rails.application.routes.draw do
...
resource :operation do
get :current
end
...
end
class UsersController < ApplicationController
...
def update
if current_operation
current_operation.complete
redirect_to users_path
end
end
end