我有act_as_follower
宝石。其中:
class Section < ActiveRecord::Base
has_many :posts
acts_as_followable
# ...
end
class User < ActiveRecord::Base
acts_as_follower
has_one :section
has_many :posts
# ...
end
SectionController:
def follow
@section = Section.find(params[:id])
@section.user = current_user
if @section.user == nil
# We don't follow this yet
@section.user.follow(@section)
msg = "You are suscribed to this Section"
elsif @section.user.following?(@section)
# We already follow this
@section.user.stop_following(@section)
msg = "You are't suscribed to this Section anymore"
else
# We don't follow this yet
@section.user.follow(@section)
msg = "You are suscribed to this Section"
end
redirect_to section_path(@section), :notice => msg
end
这一切工作正常,但我想在created_at desc
按articles.index
的顺序显示所遵循的部分的文章。