second attempt of making favorite people view sortable
This commit is contained in:
parent
f2686288b7
commit
2f6d638cd1
@ -1,11 +1,17 @@
|
|||||||
class FavoritesController < ApplicationController
|
class FavoritesController < ApplicationController
|
||||||
|
helper_method :sort_column, :sort_direction
|
||||||
|
|
||||||
def people
|
def people
|
||||||
@favorite_people = FavoritePerson.where('user_id': current_user.id)
|
@favorite_people = FavoritePerson.where('user_id': current_user.id)
|
||||||
.order(params[:sort])
|
.order(sort_column + " " + sort_direction)
|
||||||
@host = 'https://tiss.tuwien.ac.at'
|
@host = 'https://tiss.tuwien.ac.at'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete_person
|
||||||
|
FavoritePerson.find_by_tiss_id(params[:tiss_id]).destroy
|
||||||
|
redirect_back(fallback_location: people)
|
||||||
|
end
|
||||||
|
|
||||||
def courses
|
def courses
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -17,4 +23,14 @@ class FavoritesController < ApplicationController
|
|||||||
def projects
|
def projects
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def sort_column
|
||||||
|
params[:sort] || 'first_name'
|
||||||
|
end
|
||||||
|
|
||||||
|
def sort_direction
|
||||||
|
params[:direction] || 'asc'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -27,9 +27,10 @@
|
|||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Thumb</th>
|
<th>Thumb</th>
|
||||||
<th><%= link_to "First Name", :sort => "first_name" %></th>
|
<th><%= sortable "First Name", "first_name" %></th>
|
||||||
<th><%= link_to "Last Name", :sort => "last_name" %></th>
|
<th><%= sortable "Last Name", "last_name" %></th>
|
||||||
<th><%= link_to "Registration Date", :sort => "created_at" %></th>
|
<th><%= sortable "Registration Date", "created_at" %></th>
|
||||||
|
<th>Del</th>
|
||||||
</tr>
|
</tr>
|
||||||
<% for person in @favorite_people %>
|
<% for person in @favorite_people %>
|
||||||
<tr>
|
<tr>
|
||||||
@ -51,6 +52,9 @@
|
|||||||
<td>
|
<td>
|
||||||
<%= person['created_at'] %>
|
<%= person['created_at'] %>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= link_to "X", {:action => "delete_person", :tiss_id => person['tiss_id']}, :method => 'delete' %>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@ -26,6 +26,7 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
namespace :favorites do
|
namespace :favorites do
|
||||||
get 'people'
|
get 'people'
|
||||||
|
delete 'delete_person'
|
||||||
get 'courses'
|
get 'courses'
|
||||||
get 'theses'
|
get 'theses'
|
||||||
get 'projects'
|
get 'projects'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user