-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30031a9
commit 11ec70b
Showing
9 changed files
with
91 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
class EventAttendee < ApplicationRecord | ||
belongs_to :attendee, :class_name => "User" | ||
belongs_to :attended_event, :class_name => "Event" | ||
def create | ||
@attendance = EventAttendee.new(event_attendance_params) | ||
@attendance.attendee_id = current_user.id | ||
|
||
validates :attendee_id, presence: true | ||
validates :attended_event_id, presence: true | ||
respond_to do |format| | ||
if EventAttendee.where('attendee_id = ? AND attended_event_id = ?', @attendance.attendee_id, | ||
@attendance.attended_event_id).exists? | ||
format.html do | ||
redirect_to event_path(@attendance.attended_event_id), alert: "You're already attending this event." | ||
end | ||
format.json { render json: @attendance.errors, status: :unprocessable_entity } | ||
elsif @attendance.save | ||
format.html do | ||
redirect_to event_path(@attendance.attended_event_id), notice: 'Attendance was successfully confirmed.' | ||
end | ||
format.json { render :show, status: :created, location: @event } | ||
else | ||
format.html { render :show, status: :unprocessable_entity } | ||
format.json { render json: @event.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def event_attendance_params | ||
params.require(:event_attendance).permit(:attended_event_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<%= form_with(model: attendance) do |form| %> | ||
<div class="field"> | ||
<%= form.hidden_field :attended_event_id, value: @event.id %> | ||
</div> | ||
|
||
<div class="actions"> | ||
<%= form.submit "Attend this Event"%> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,24 @@ | ||
<div class="columns"> | ||
<div class="column is-11 is-offset-1"> | ||
<div class="column is-10 is-offset-1"> | ||
<h1 class="title mt-4">All Events</h1> | ||
<div class="columns"> | ||
<div class="column is-two-fifths"> | ||
<div class="column"> | ||
<div class="subtitle is-5 mt-4">Upcoming Events:</div> | ||
<div class="upcoming"> | ||
<ul> | ||
<ul> | ||
<%= show_event_list(@upcoming_events) %> | ||
</ul> | ||
<button class="button is-primary is-light">Read More</button> | ||
</div> | ||
</div> | ||
<div class="column"></div> | ||
|
||
<div class="column is-two-fifths"> | ||
<div class="column"> | ||
<div class="subtitle mt-4">Past Events:</div> | ||
<div class="upcoming"> | ||
<ul> | ||
<%= show_event_list(@past_events) %> | ||
</ul> | ||
<button class="button is-primary is-light">Read More</button> | ||
</div> | ||
</div> | ||
</div> | ||
<p class="button is-info is-light mt-6"> | ||
<%= link_to 'New Event', new_event_path %> | ||
<p class="button is-primary is-light mt-6"> | ||
<%= link_to 'New Event', new_event_path, class: 'a-reset' %> | ||
</p> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Rails.application.routes.draw do | ||
get 'user/show' | ||
get "/users/:id", to: "users#show", :as => :user_show | ||
devise_for :users, :controllers => { registrations: 'registrations' } | ||
resources :events | ||
resources :event_attendances | ||
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html | ||
root "events#index" | ||
end |