Implement favoriting of projects

This commit is contained in:
2020-05-29 10:29:20 +02:00
parent c9f93d6fd8
commit 04245d63dc
8 changed files with 86 additions and 4 deletions
+7
View File
@@ -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
+5
View File
@@ -0,0 +1,5 @@
class FavoriteProject < ApplicationRecord
self.primary_key = 'id'
validates :id, uniqueness: true
end
+33 -2
View File
@@ -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 %>