Created
January 6, 2015 02:50
-
-
Save gogogarrett/8b170fd6cfc43bf55552 to your computer and use it in GitHub Desktop.
Reform + Wicked Integration
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
class AfterSignupController < ApplicationController | |
include Wicked::Wizard | |
steps :create_organization, :create_event, :create_tiers | |
def show | |
case step | |
when :create_organization | |
@form = Form::Organization.new(Organization.new) | |
when :create_event | |
@form = Form::Event.new(Event.new) | |
when :create_tiers | |
@form = Form::Tier.new(Tier.new) | |
end | |
render_wizard | |
end | |
def update | |
case step | |
when :create_organization | |
@form = Form::Organization.new(Organization.new) | |
Service::CreateOrganization.new(@form, params[:organization], current_user).call | |
when :create_event | |
@form = Form::Event.new(Event.new) | |
Service::CreateEvent.new(@form, params[:event], current_user).call | |
when :create_tiers | |
@form = Form::Tier.new(Tier.new) | |
@event = new_org_event | |
Service::CreateTier.new(@form, params[:tier], @event).call | |
end | |
render_wizard @form | |
end | |
def finish_wizard_path | |
event_path(new_org_event) | |
end | |
private | |
def new_org_event | |
@event ||= Organization.includes(users: :events).find_by('users.id' => current_user.id).events.first | |
end | |
end |
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
module Form | |
class Event < Reform::Form | |
model :event | |
property :title | |
property :desc | |
property :creator | |
validates :title, :desc, :creator, presence: true | |
end | |
end |
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
module Service | |
class CreateEvent | |
def initialize(form, params, user) | |
@form, @params, @user = form, params, user | |
end | |
def call | |
form.save if form.validate(params.merge(creator: user)) | |
form.model | |
end | |
private | |
attr_reader :form, :params, :user | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment