Last active
September 12, 2017 13:20
-
-
Save abhchand/883015f2e39639158ab7dd56b7030b55 to your computer and use it in GitHub Desktop.
Revisions
-
abhchand revised this gist
Sep 10, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -56,6 +56,6 @@ def handle_email_format_invalid end def handle_success # n/a end end -
abhchand revised this gist
Sep 10, 2017 . 1 changed file with 4 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,9 @@ class UsersController < ApplicationController def create validator = UsersCreateActionInteractor.call(params: user_params) unless validator.success? flash[:error] = validator.err_msg redirect_to(new_users_path) return end @@ -22,9 +23,4 @@ def user_params :email ) end end -
abhchand revised this gist
Sep 10, 2017 . 2 changed files with 41 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ class UsersController < ApplicationController def create # Validate the form data and return if it is not correct unless create_action_validation.success? flash[:error] = create_action_validation.err_msg 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 def create_action_validation @create_action_validation || = UsersCreateActionInteractor.call(params: user_params) end end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ class UsersCreateActionInteractor include Interactor @@ -22,31 +21,38 @@ def name_is_blank? end def handle_blank_name # Note: The interactor gem supports a short-hand notation for # the below actions: # > context.fail!(err_msg: "...") context.err_msg = "Please fill in a name" context.fail! end def email_is_blank? @params[:email].blank? end def handle_blank_email context.err_msg = "Please fill in an email" context.fail! end def email_is_taken? User.find_by_email(@params[:email]).any? end def handle_email_is_taken context.err_msg = "That email already exists!" context.fail! end def email_format_invalid? (@params[:email] =~ /.*@.*\..*/i).blank? end def handle_email_format_invalid context.err_msg = "Sorry, that doesn't look like an email address" context.fail! end def handle_success -
abhchand revised this gist
Sep 10, 2017 . 1 changed file with 52 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,55 @@ # app/interactors/users_create_action_interactor.rb class UsersCreateActionInteractor include Interactor def call @params = context.params case when name_is_blank? then handle_blank_name when email_is_blank? then handle_blank_email when email_is_taken? then handle_email_is_taken when email_format_invalid? then handle_email_format_invalid else handle_success end end private def name_is_blank? @params[:first_name].blank? || @params[:last_name].blank? end def handle_blank_name context.fail!(err_msg: "Please fill in a name") end def email_is_blank? @params[:email].blank? end def handle_blank_email context.fail!(err_msg: "Please fill in an email") end def email_is_taken? User.find_by_email(@params[:email]).any? end def handle_email_is_taken context.fail!(err_msg: "That email already exists!") end def email_format_invalid? (@params[:email] =~ /.*@.*\..*/i).blank? end def handle_email_format_invalid context.fail!(err_msg: "Sorry, that doesn't look like an email address") end def handle_success # tbd end end -
abhchand revised this gist
Sep 10, 2017 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ # app/interactors/users_create_action_interactor.rb class UsersCreateActionInteractor include Interactor end -
abhchand revised this gist
Sep 9, 2017 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,8 @@ 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) -
abhchand created this gist
Sep 9, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ class UsersController < ApplicationController def create # Validate the form data and return if # it is not correct 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