我已按照以下步骤安装 gem:
rails generate devise:install
rails generate devise User
rails generate simple_private_messages:model User Message
将此行 (has_private_messages) 添加到用户模型:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
has_private_messages
结尾
编辑 routes.rb 文件,这里的顺序很重要,devise_for 应该在消息路由之前定义。
devise_for :users
resources :users do
resources :messages do
collection do
post :delete_selected
end
end
end
如果你想要脚手架:
rails generate simple_private_messages:scaffold User Message
并记住取消注释(attr_accessor :to):
class Message < ActiveRecord::Base
is_private_message
# The :to accessor is used by the scaffolding,
# uncomment it if using it or you can remove it if not
attr_accessor :to
end