scinote-web/app/controllers/users/settings_controller.rb

30 lines
751 B
Ruby
Raw Normal View History

2017-02-09 22:10:45 +08:00
module Users
class SettingsController < ApplicationController
before_action :load_user, only: [
:user_current_team
]
2016-02-12 23:52:43 +08:00
2017-02-09 22:10:45 +08:00
def user_current_team
team_id = params[:user][:current_team_id].to_i
if @user.teams_ids.include?(team_id)
@user.current_team_id = team_id
@changed_team = Team.find_by_id(@user.current_team_id)
if @user.save
flash[:success] = t('users.settings.changed_team_flash',
team: @changed_team.name)
redirect_to root_path
return
end
end
2017-02-09 22:10:45 +08:00
flash[:alert] = t('users.settings.changed_team_error_flash')
redirect_to :back
end
2017-02-09 22:10:45 +08:00
private
2016-02-12 23:52:43 +08:00
2017-02-09 22:10:45 +08:00
def load_user
@user = current_user
end
2016-02-12 23:52:43 +08:00
end
end