diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index a6de6a3..54e4275 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -1,11 +1,17 @@ class FavoritesController < ApplicationController + helper_method :sort_column, :sort_direction def people @favorite_people = FavoritePerson.where('user_id': current_user.id) - .order(params[:sort]) + .order(sort_column + " " + sort_direction) @host = 'https://tiss.tuwien.ac.at' end + def delete_person + FavoritePerson.find_by_tiss_id(params[:tiss_id]).destroy + redirect_back(fallback_location: people) + end + def courses end @@ -17,4 +23,14 @@ class FavoritesController < ApplicationController def projects end + + private + + def sort_column + params[:sort] || 'first_name' + end + + def sort_direction + params[:direction] || 'asc' + end end diff --git a/app/views/favorites/people.html.erb b/app/views/favorites/people.html.erb index edfa364..5e5de03 100644 --- a/app/views/favorites/people.html.erb +++ b/app/views/favorites/people.html.erb @@ -27,9 +27,10 @@
| Thumb | -<%= link_to "First Name", :sort => "first_name" %> | -<%= link_to "Last Name", :sort => "last_name" %> | -<%= link_to "Registration Date", :sort => "created_at" %> | +<%= sortable "First Name", "first_name" %> | +<%= sortable "Last Name", "last_name" %> | +<%= sortable "Registration Date", "created_at" %> | +Del |
|---|---|---|---|---|---|---|---|
| <%= person['created_at'] %> | ++ <%= link_to "X", {:action => "delete_person", :tiss_id => person['tiss_id']}, :method => 'delete' %> + |