Skip to content

Instantly share code, notes, and snippets.

@abhchand
Last active September 12, 2017 13:20
Show Gist options
  • Select an option

  • Save abhchand/883015f2e39639158ab7dd56b7030b55 to your computer and use it in GitHub Desktop.

Select an option

Save abhchand/883015f2e39639158ab7dd56b7030b55 to your computer and use it in GitHub Desktop.
Blog Post: The interactor design pattern
class UsersController < ApplicationController
def create
# Validate the form data and return if it is not correct
# We'll come back and fill in the ???? with the call to the
# interactor shortly.
unless (????)
flash[:error] = ????
redirect_to(new_users_path)
return
end
user = User.create!(user_params)
flash[:success] = "Woohoo, you created an account"
redirect_to(user_path(@ser))
end
private
def user_params
@user_params || = params.require(:user).permit(
:first_name,
:last_name,
:email
)
end
end
# app/interactors/users_create_action_interactor.rb
class UsersCreateActionInteractor
include Interactor
end
@abhchand
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment