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 descarticles.index.

4

0 回答 0