from a before_action method if !current_user.is_old_enough_to_join_group?(@group) flash[:alert] = I18n.t('admin.trestle.flash.too_young') elsif current_user.is_group_limit_reached? flash[:alert] = I18n.t('admin.trestle.flash.too_many_groups') else user_group = UserGroup.new(user_id: current_user.id, group_id: @group.id) if user_group.save flash[:notice] = I18n.t('admin.trestle.flash.successfully_joined_group') else flash[:alert] = I18n.t('admin.trestle.flash.could_not_join_group') end end redirect_to group_path(@group) end end
has_many :groups, through: :user_groups def is_old_enough_to_join_group?(group) age > group.minimum_age end def is_group_limit_reached? groups.count >= MAX_NUMBER_OF_GROUPS end end
characters. Email Must have valid format as in the example: [email protected]. Password At least 6 characters, maximum 15 characters. Password Confirmation Must be filled in identically to the password. Main Flow - Set of steps Exception Flow - What happened when things do not go well
user: current_user message = result.message if result.success? flash[:notice] = message else flash[:alert] = message end redirect_to group_path(@group) end end