users_controller.rb:
class UsersController < ApplicationController def new end def create user = User.create(params[:user]) if user.id session[:user_id] = user.id redirect_to '/city/map' else redirect_to new_session_path, flash: { error: 'This name is already taken.' } end end end sessions_controller.rb:
class SessionsController < ApplicationController def new end def create user = User.new(params[:session]).authorize if user session[:user_id] = user.id redirect_to '/city/map' else redirect_to new_session_path, flash: { error: 'Your login information is invalid.' } end end def destroy end end How can I DRY it (only in terms of repeatable code in create actions in these controllers)?