Skip to content

Commit

Permalink
Don't create default user. Create when agree to terms of service
Browse files Browse the repository at this point in the history
  • Loading branch information
kinoppyd committed Mar 27, 2024
1 parent 6e4624d commit b05d484
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
18 changes: 6 additions & 12 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,15 @@ class ApplicationController < ActionController::Base
rescue_from ActionController::RoutingError, with: :not_found

def set_user
if session[:user_id]
@user = User.find(session[:user_id])
else
create_and_set_user
end
rescue ActiveRecord::RecordNotFound
create_and_set_user
@user = User.find(session[:user_id]) if session[:user_id]
end

def set_plan
@plan = @user.plans.where(event: @event).recent&.first ||
@user.plans.build(title: "My RubyKaigi #{@event.name} set list",
description: "Enjoy my RubyKaigi #{@event.name} set list",
public: true,
event: @event)
@plan = (@user && @user.plans.where(event: @event).recent&.first) ||
Plan.new(title: "My RubyKaigi #{@event.name} set list",
description: "Enjoy my RubyKaigi #{@event.name} set list",
public: true,
event: @event)
end

def not_found(err)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def editable
end

def create
create_and_set_user unless @user
@plan = @user.plans.where(event: @event).create!(plan_params)
add_and_remove_plans if plan_add_or_remove?
redirect_to event_schedules_path(event_name: @plan.event.name)
Expand Down

0 comments on commit b05d484

Please sign in to comment.