Implement favoriting of projects
This commit is contained in:
parent
c9f93d6fd8
commit
04245d63dc
@ -35,7 +35,14 @@ class FavoritesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def projects
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
5
app/models/favorite_project.rb
Normal file
5
app/models/favorite_project.rb
Normal file
@ -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 %>
|
||||||
|
|||||||
@ -48,7 +48,7 @@ Rails.application.routes.draw do
|
|||||||
get 'theses'
|
get 'theses'
|
||||||
delete 'delete_thesis'
|
delete 'delete_thesis'
|
||||||
get 'projects'
|
get 'projects'
|
||||||
delete 'delete_projects'
|
delete 'delete_project'
|
||||||
end
|
end
|
||||||
|
|
||||||
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
|
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
|
||||||
|
|||||||
12
db/migrate/20200529081537_create_favorite_projects.rb
Normal file
12
db/migrate/20200529081537_create_favorite_projects.rb
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
class CreateFavoriteProjects < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
create_table :favorite_projects, id: false do |t|
|
||||||
|
t.integer :id, null: false
|
||||||
|
t.integer :user_id, null: false
|
||||||
|
t.string :title
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :favorite_projects, :id, unique: true
|
||||||
|
end
|
||||||
|
end
|
||||||
11
db/schema.rb
11
db/schema.rb
@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2020_05_25_132942) do
|
ActiveRecord::Schema.define(version: 2020_05_29_081537) do
|
||||||
|
|
||||||
create_table "favorite_courses", force: :cascade do |t|
|
create_table "favorite_courses", force: :cascade do |t|
|
||||||
t.string "number", null: false
|
t.string "number", null: false
|
||||||
@ -33,6 +33,15 @@ ActiveRecord::Schema.define(version: 2020_05_25_132942) do
|
|||||||
t.index ["tiss_id"], name: "index_favorite_people_on_tiss_id", unique: true
|
t.index ["tiss_id"], name: "index_favorite_people_on_tiss_id", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "favorite_projects", id: false, force: :cascade do |t|
|
||||||
|
t.integer "id", null: false
|
||||||
|
t.integer "user_id", null: false
|
||||||
|
t.string "title"
|
||||||
|
t.datetime "created_at", precision: 6, null: false
|
||||||
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
|
t.index ["id"], name: "index_favorite_projects_on_id", unique: true
|
||||||
|
end
|
||||||
|
|
||||||
create_table "favorite_theses", id: false, force: :cascade do |t|
|
create_table "favorite_theses", id: false, force: :cascade do |t|
|
||||||
t.integer "id", null: false
|
t.integer "id", null: false
|
||||||
t.integer "user_id", null: false
|
t.integer "user_id", null: false
|
||||||
|
|||||||
11
test/fixtures/favorite_projects.yml
vendored
Normal file
11
test/fixtures/favorite_projects.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
# This model initially had no columns defined. If you add columns to the
|
||||||
|
# model remove the '{}' from the fixture names and add the columns immediately
|
||||||
|
# below each fixture, per the syntax in the comments below
|
||||||
|
#
|
||||||
|
one: {}
|
||||||
|
# column: value
|
||||||
|
#
|
||||||
|
two: {}
|
||||||
|
# column: value
|
||||||
7
test/models/favorite_project_test.rb
Normal file
7
test/models/favorite_project_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class FavoriteProjectTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user