Skip to content

Commit

Permalink
Update the helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
VanessaAoki committed May 5, 2021
1 parent 526a273 commit ec735a8
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 54 deletions.
7 changes: 0 additions & 7 deletions app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,4 @@ def show
@user_events = @user.created_at
@user_attendance = @user.attended_events
end

def show
@user = User.find(params[:id])
@past_events = @user.attended_event.all_past_events
@upcoming_events = @user.attended_event.all_upcoming_events
end

end
3 changes: 0 additions & 3 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ def navbar_user_control
if user_signed_in?
out += link_to 'Create Event', new_event_url, class: 'button is-primary is-inverted'
out += "<p class=\"control\">"
out += link_to 'Your Events', user_path, class: 'button is-primary'
out += "</p>"
out += "<p class=\"control\">"
out += link_to current_user.username, edit_user_registration_path, class: 'button is-primary'
out += "</p>"
out += "<p>"
Expand Down
7 changes: 3 additions & 4 deletions app/helpers/events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ def show_attendee_lists(_attendees)
end

def event_controls(event)
out = ''
out = '<div class="is-flex mb-3">'
if user_signed_in? && current_user.id == event.creator_id
out += '<div class="is-flex mb-3">'
out += link_to 'Edit', edit_event_path(@event), class: 'button is-warning is-outlined mr-2'
out += button_to 'Delete', event, method: :delete, data: { confirm: 'Are you sure?' },
class: 'button is-danger is-outlined mr-2'
out += link_to 'Back', events_path, class: 'button is-outlined'
out += '</div>'
end
out += link_to 'Back', events_path, class: 'button is-outlined'
out += '</div>'
out.html_safe
end

Expand Down
18 changes: 2 additions & 16 deletions app/helpers/user_helper.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
module UsersHelper
def show_event_list(events)
out = ''
events.each do |event|
out += "<ul><li><strong>Event Name:</strong> #{event.name}</li>"
out += "<li>Description: #{event.description}</li>"
out += "<li>Date: #{event.date}</li>"
out += "<li>Location: #{event.location}</li></ul>"
end
out.html_safe
end

def display_events(events, partial_to_render, title_to_display)
render partial: partial_to_render, locals: { events: events, title: title_to_display }
if events.size.positive?
end
module UserHelper

end
2 changes: 1 addition & 1 deletion app/views/events/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</p>

<p class="my-4">
<%= event_controls(@event) %>
<%= event_controls(@event) %>
</p>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<div class="navbar-brand">
<%= link_to root_path, class: "navbar-item" do %>
<h1 class="title is-4 has-text-white">Private Events</h1>
<% end %>
<%= link_to 'Your events', event_attendees_path(@event_attendees) %>
<% end %>
<div class="navbar-burger burger" data-target="navbarExample">
<span></span>
<span></span>
Expand Down
24 changes: 3 additions & 21 deletions app/views/user/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
<p>
<strong>Name:</strong>
<%= @user.name %>
</p>

<p>
<strong>Username:</strong>
<%= @user.username %>
Expand All @@ -14,25 +9,12 @@
</p>

<br>

<%#
<strong><u>Created Events:</u></strong>
<%= show_event_list(@user_events) %><br>
<%= show_event_list(@user_events) %><br> %>

<strong><u>Event Attendances:</u></strong><br><br>

<strong>Upcoming Events:</strong><ol>
<% @user_attendance.each do |attendance| %>
<% if attendance.date > Time.now %>
<li><strong><%= attendance.name %></strong>, <%= attendance.location %></li>
<% end %>
<% end %>
</ol>
<strong>Past Events:</strong><ol>
<% @user_attendance.each do |attendance| %>
<% if attendance.date < Time.now %>
<li><strong><%= attendance.name %></strong>, <%= attendance.location %></li>
<% end %>
<% end %>
</ol><br>


<%= link_to 'Back', events_path %>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
root "events#index"
resources :events
resources :event_attendees, only: [:create, :destroy]
get "/users/:id", to: "users#show", :as => :user_show
get 'event_attendees/:id', to: 'user#show'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end

0 comments on commit ec735a8

Please sign in to comment.