followers_controller.rb
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class FollowersController < MyProfileController
before_filter :only_for_person, :only => :index
def index
@followed_people = current_person.following_profiles.order(:type).paginate(:per_page => 15, :page => params[:npage])
end
def set_category_modal
categories = FollowCategory.where(:person => current_person).map(&:name)
profile = Profile.find(params[:followed_profile_id])
render :partial => 'blocks/profile_info_actions/follow_categories', :locals => { :categories => categories, :profile => profile }
end
def update_category
params["followed_profile_id"] ||= profile.id
follower = ProfileFollower.find_by(follower_id: current_person.id, profile_id: params[:followed_profile_id])
if params[:category_name]
category = FollowCategory.find_or_create_by(:name => params[:category_name], :person => current_person)
else
category = nil
end
if follower
follower.follow_category = category
follower.save
end
redirect_url = params["redirect_to"] ? params["redirect_to"] : url_for(:controller => "followers", :action => "index", :profile => current_person.identifier)
redirect_to redirect_url
end
protected
def only_for_person
render_not_found unless profile.person?
end
end