Files
danbooru/app/controllers/recommended_posts_controller.rb
evazion 41b30fc64c recommendations: open user recommendations to all users.
* Open recommendations to all users (not just gold).
* Show recommendations on all posts (not just posts after 2017).
* Allow users to browse recommendations for other users.
* Increase number of recommended posts returned.
* Change endpoints to /recommended_posts?user_id=1234 and
  /recommended_posts?post_id=1234 and add json/xml support.
2019-12-01 00:44:04 -06:00

19 lines
560 B
Ruby

class RecommendedPostsController < ApplicationController
respond_to :html, :json, :xml, :js
def show
@max_recommendations = params.fetch(:max_recommendations, 100).to_i.clamp(0, 1000)
if params[:user_id].present?
@recs = RecommenderService.recommend_for_user(params[:user_id], @max_recommendations)
elsif params[:post_id].present?
@recs = RecommenderService.recommend_for_post(params[:post_id], @max_recommendations)
else
@recs = []
end
@posts = @recs.map { |rec| rec[:post] }
respond_with(@recs)
end
end