Implement favoriting of projects
This commit is contained in:
@@ -35,7 +35,14 @@ class FavoritesController < ApplicationController
|
||||
end
|
||||
|
||||
def projects
|
||||
@favorite_projects = FavoriteProject.where('user_id': current_user.id)
|
||||
.order(sort_column + " " + sort_direction)
|
||||
@host = 'https://tiss.tuwien.ac.at'
|
||||
end
|
||||
|
||||
def delete_project
|
||||
FavoriteProject.find_by(id: params[:id]).destroy
|
||||
redirect_back(fallback_location: projects)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class FavoriteProject < ApplicationRecord
|
||||
self.primary_key = 'id'
|
||||
|
||||
validates :id, uniqueness: true
|
||||
end
|
||||
@@ -1,3 +1,34 @@
|
||||
<%= render(:partial => "nav")%>
|
||||
<%= render(:partial => "nav") %>
|
||||
|
||||
<p>Fav Projects</p>
|
||||
<h1>Favorite Projects</h1>
|
||||
|
||||
<% if !@favorite_projects[0].blank? %>
|
||||
<div class="table_wrapper">
|
||||
<table>
|
||||
<tr>
|
||||
<th><%= sortable "Title", "title" %></th>
|
||||
<th><%= sortable "Registration Date", "created_at" %></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<% for project in @favorite_projects %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= project['title'] %>
|
||||
</td>
|
||||
<td>
|
||||
<%= project['created_at'] %>
|
||||
</td>
|
||||
<td>
|
||||
<%= button_to 'Details', crawlers_projects_crawler_show_detail_url(:id => project['id']) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= button_to 'Delete', {:action => "delete_project", :id => project['id']}, :method => 'delete' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
</div>
|
||||
<% else %>
|
||||
No favorite projects added yet!
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user