0

私は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

セクションコントローラー:

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

4

0 に答える 0