tiss2go/app/controllers/favorites_controller.rb

58 lines
1.5 KiB
Ruby

class FavoritesController < ApplicationController
helper_method :sort_column, :sort_direction
def people
@favorite_people = FavoritePerson.where('user_id': current_user.id)
.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
@favorite_courses = FavoriteCourse.where('user_id': current_user.id)
.order(sort_column + " " + sort_direction)
@host = 'https://tiss.tuwien.ac.at'
end
def delete_course
FavoriteCourse.find_by(number: params[:number], semester: params[:semester]).destroy
redirect_back(fallback_location: courses)
end
def theses
@favorite_theses = FavoriteThesis.where('user_id': current_user.id)
.order(sort_column + " " + sort_direction)
@host = 'https://tiss.tuwien.ac.at'
end
def delete_thesis
FavoriteThesis.find_by(id: params[:id]).destroy
redirect_back(fallback_location: theses)
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
def sort_column
params[:sort] || ''
end
def sort_direction
params[:direction] || ''
end
end