You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/controllers/users/interests_controller.rb

26 lines
913 B

class Users::InterestsController < Users::BaseController
6 years ago
skip_before_action :check_observed_user_exists!
before_action :require_login
def create
return render_forbidden if current_user.user_extension&.identity.present?
identity = params[:identity].to_s.strip
6 years ago
extension = current_user.user_extension || current_user.build_user_extension
return render_error('请选择职业') unless %w(teacher student professional).include?(identity)
ActiveRecord::Base.transaction do
extension.update_column(:identity, identity)
# 兴趣
6 years ago
current_user.user_interests.delete_all
UserInterest.bulk_insert(:user_id, :repertoire_id) do |worker|
(Repertoire.pluck(:id) & Array.wrap(params[:interest_ids]).map(&:to_i)).each do |repertoire_id|
6 years ago
worker.add(user_id: current_user.id, repertoire_id: repertoire_id)
end
end
end
render_ok
end
end