-
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.
Change events attendees views, controllers and route, fix the attend …
…button
- Loading branch information
1 parent
a28741b
commit 267ea99
Showing
12 changed files
with
81 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,15 @@ | ||
class EventAttendee < ApplicationRecord | ||
def create | ||
@attendance = EventAttendance.new(event_attendance_params) | ||
@attendance.attendee_id = current_user.id | ||
class EventAttendeesController < ApplicationController | ||
|
||
respond_to do |format| | ||
if EventAttendance.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 | ||
def create | ||
@event = Event.find(params[:event_attendee][:attended_event_id]) | ||
current_user.attend!(@event) | ||
redirect_to @event | ||
end | ||
|
||
private | ||
def destroy | ||
@event = EventAttendee.find(params[:id]).attended_event | ||
current_user.cancel!(@event) | ||
redirect_to @event | ||
end | ||
|
||
def event_attendance_params | ||
params.require(:event_attendance).permit(:attended_event_id) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
class UserController < ApplicationController | ||
def show | ||
@user = User.find(params[:id]) | ||
@user_events = @user.created_events | ||
@user_attendance = @user.attended_events | ||
@events = @user.events.paginate(page: params[:page]) | ||
@upcoming_events = @user.upcoming_events | ||
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
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,9 +1,6 @@ | ||
<%= 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 %> | ||
<% if user_signed_in? %> | ||
<%= form_for(current_user.event_attendees.build(attended_event_id: @event.id)) do |f| %> | ||
<%= f.hidden_field :attended_event_id %> | ||
<%= f.submit "Attend", class: "btn btn-sm btn-primary" %> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% if user_signed_in? && current_user.attending?(@event) %> | ||
<%= render 'cancel' %> | ||
<% else %> | ||
<%= render 'attend' %> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= form_for(current_user.event_attendees.find_by(attended_event_id: @event.id), | ||
html: { method: :delete }) do |f| %> | ||
<%= f.submit "Cancel", class: "btn btn-sm btn-default" %> | ||
<% 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,31 +1,36 @@ | ||
<p> | ||
<strong>Title:</strong> | ||
<%= @event.title %> | ||
</p> | ||
<div class="columns"> | ||
<div class="column columns is-half is-offset-one-quarter box mt-6"> | ||
<div class="column is-10 is-offset-1"> | ||
<p class="title"> | ||
<%= @event.title %> | ||
</p> | ||
|
||
<p> | ||
<strong>Description:</strong> | ||
<%= @event.description %> | ||
</p> | ||
<p> | ||
Description: | ||
<%= @event.description %> | ||
</p> | ||
|
||
<p> | ||
<strong>Date:</strong> | ||
<%= @event.date %> | ||
</p> | ||
<p> | ||
Date: | ||
<%= @event.date %> | ||
</p> | ||
|
||
<p> | ||
<strong>Location:</strong> | ||
<%= @event.location %> | ||
</p> | ||
<p> | ||
Location: | ||
<%= @event.location %> | ||
</p> | ||
|
||
<br> | ||
<%= show_attendance_button(@event, @attendance) %> | ||
<p> | ||
<%= render 'attend_cancel' %> | ||
</p> | ||
|
||
<strong>Attendees:</strong> | ||
Attendees: | ||
|
||
<ol> | ||
<%= show_attendee_lists(@attendees) %> | ||
</ol> | ||
<ol> | ||
<%= show_attendee_lists(@attendees) %> | ||
</ol> | ||
|
||
<br> | ||
<%= event_controls(@event) %> | ||
<%= event_controls(@event) %> | ||
</div> | ||
</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