mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
upto 3.11: added option to join to beerclub
This commit is contained in:
@@ -30,6 +30,9 @@ class MembershipsController < ApplicationController
|
||||
format.html { redirect_to membership_url(@membership), notice: "Membership was successfully created." }
|
||||
format.json { render :show, status: :created, location: @membership }
|
||||
else
|
||||
# TODO maybe doing something wrong but the variables of new need to be reinitialized here :D
|
||||
@users = User.all
|
||||
@beerclubs = Beerclub.all
|
||||
format.html { render :new, status: :unprocessable_entity }
|
||||
format.json { render json: @membership.errors, status: :unprocessable_entity }
|
||||
end
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
class Membership < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :beerclub
|
||||
|
||||
validate :user_not_in_club
|
||||
|
||||
def user_not_in_club
|
||||
if not Membership.find_by(user_id:user_id, beerclub_id:beerclub_id).nil?
|
||||
errors.add :user_id, "is already in the beerclub"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
<% end %>
|
||||
|
||||
<div>
|
||||
<%= form.label :user_id, style: "display: block" %>
|
||||
<%= form.select :user_id, options_from_collection_for_select(@users, :id, :username) %>
|
||||
<%= form.label :user_id, style: "display: block" %>
|
||||
<%= form.select :user_id, options_from_collection_for_select(@users, :id, :username) %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user