Как сделать так, чтобы пользователи автоматически следовали за администратором при регистрации

В настоящее время я разрешаю пользователям следить друг за другом в моем приложении rails(похоже на твиттер).

Я был бы рад, если бы новые пользователи, которые регистрируются на сайте, автоматически следовали за администратором

Similar to how MySpace use to automatically make Tom your first friend

Ниже приведен код, который я использую для создания новых пользователей и предоставления пользователям возможности следовать друг за другом (я знаю, что это очень широкий вопрос, но .....)

(Может кто-то указать мне правильное направление на то, как я могу начать это. Нужно ли мне создавать метод .... в моих моделях или добавлять код в контроллер?)

Новичок в Rails Пожалуйста, помогите) ... :)

ПОЛЬЗОВАТЕЛЬСКИЙ КОНТРОЛЛЕР

class UsersController < ApplicationController
  before_filter :admin_user,     only: [:destroy]

  respond_to :html, :js

  def new
    @user = RegularUser.new
  end

  def index
    @users = User.paginate(page: params[:page], :per_page => 100).search(params[:search])
  end

  def destroy
    User.find_by_username(params[:id]).destroy
    flash[:success] = "User destroyed."
    redirect_to users_url
  end

  def create
    @user = RegularUser.new(params[:regular_user])
    if @user.save
      UserMailer.registration_confirmation(@user).deliver
      UserMailer.welcome_user(@user).deliver
      sign_in @user
      flash[:success] = "Welcome to the ClickOnComics!"
      redirect_to (publishers_path)
    else
      render 'new'
    end
  end

  private

    def admin_user
      redirect_to(root_path) unless current_user.admin?
    end

    def follow_admins
      admins = User.find_by_admin(true)
      admins.each do |admin|
      self.follow!(admin)
    end
end

class RelationshipsController < ApplicationController
  before_filter :current_user

  respond_to :html, :js

 def create
   @user = User.find(params[:relationship][:followed_id])
    current_user.follow!(@user)
   respond_with @user
 end

  def destroy
    @user = Relationship.find(params[:id]).followed
    current_user.unfollow!(@user)
    respond_with @user
  end

end

МОДЕЛИ

class Relationship < ActiveRecord::Base

  attr_accessible :followed_id

  belongs_to :follower, class_name: "User"
  belongs_to :followed, class_name: "User"

  validates :follower_id, presence: true
  validates :followed_id, presence: true
end

class User < ActiveRecord::Base
  attr_accessible :name, :email, :password, :password_confirmation

  has_many :relationships, foreign_key: "follower_id", dependent: :destroy
  has_many :followed_users, through: :relationships, source: :followed

  has_many :reverse_relationships, foreign_key: "followed_id",
                               class_name:  "Relationship",
                               dependent:   :destroy
  has_many :followers, through: :reverse_relationships, source: :follower

  after_create :follow_admins

  def follow_admins
    admins = User.find_all_by_admin(true)
      admins.each do |admin|
      self.follow!(admin)
    end
  end

  def following?(other_user)
    relationships.find_by_followed_id(other_user.id)
  end

  def follow!(other_user)
    relationships.create!(followed_id: other_user.id)
  end

  def unfollow!(other_user)
    relationships.find_by_followed_id(other_user.id).destroy
  end

end

Я использовал этот учебник, чтобы помочь мне установить привилегированных административных пользователей с логическим атрибутом admin в модели User

http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-users#sec-administrative_users

SCHEMA

  create_table "users", :force => true do |t|
    t.string    "name"
    t.string    "email"
    t.string    "role"
    t.string    "username"
    t.timestamp "created_at",                                :null => false
    t.timestamp "updated_at",                                :null => false
    t.boolean   "admin",                  :default => false
    t.string    "password_reset_token"
    t.timestamp "password_reset_sent_at"
  end

Нужно ли мне создать метод, который определяет user_admin?

Ответы на вопрос(2)

Ваш ответ на вопрос