second attempt of making favorite people view sortable
This commit is contained in:
parent
f2686288b7
commit
2f6d638cd1
@ -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
|
||||
|
||||
@ -27,9 +27,10 @@
|
||||
<table>
|
||||
<tr>
|
||||
<th>Thumb</th>
|
||||
<th><%= link_to "First Name", :sort => "first_name" %></th>
|
||||
<th><%= link_to "Last Name", :sort => "last_name" %></th>
|
||||
<th><%= link_to "Registration Date", :sort => "created_at" %></th>
|
||||
<th><%= sortable "First Name", "first_name" %></th>
|
||||
<th><%= sortable "Last Name", "last_name" %></th>
|
||||
<th><%= sortable "Registration Date", "created_at" %></th>
|
||||
<th>Del</th>
|
||||
</tr>
|
||||
<% for person in @favorite_people %>
|
||||
<tr>
|
||||
@ -51,6 +52,9 @@
|
||||
<td>
|
||||
<%= person['created_at'] %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to "X", {:action => "delete_person", :tiss_id => person['tiss_id']}, :method => 'delete' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
@ -26,6 +26,7 @@ Rails.application.routes.draw do
|
||||
|
||||
namespace :favorites do
|
||||
get 'people'
|
||||
delete 'delete_person'
|
||||
get 'courses'
|
||||
get 'theses'
|
||||
get 'projects'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user