设计和简单的私人消息

发布于 2024-11-05 19:21:43 字数 843 浏览 2 评论 0原文

我在 Ruby on Rails 3 应用程序中使用 Devise 。我正在尝试在我的应用程序中实现私人消息传递,并且遇到了这个宝石:

https://github。 com/jongilbraith/simple-private-messages

我(不小心)运行了以下命令。

rails generate simple_private_messages:model User Message

它创建了消息模型。但它更改了我使用 Devise 使用以下命令生成的现有用户模型的一些属性:

    rails generate devise User

现在,当我启动 Ruby on Rails 应用程序时,我收到此警告:

[警告]您提供了 devise_for :users 但应用程序中没有定义模型 User

并且我的 Devise 链接已停止工作:

ActionView::Template::Error(#<#:0x1064c9490> 的未定义局部变量或方法“edit_user_registration_path”):

有人可以建议我如何集成两者或在无法同时使用它们的情况下恢复我的更改吗?

I am using Devise in my Ruby on Rails 3 application. I am trying to implement private messaging in my application and I came across this gem:

https://github.com/jongilbraith/simple-private-messages

I (accidentally) ran the following command.

rails generate simple_private_messages:model User Message

It created the Message model. But it changed some properties of my existing User model that I had generated using Devise using the following command:

    rails generate devise User

Now, when I start my Ruby on Rails application I get this warning:

[WARNING] You provided devise_for :users but there is no model User defined in your application

And my Devise links have stopped working:

ActionView::Template::Error (undefined local variable or method `edit_user_registration_path' for #<#:0x1064c9490>):

Can someone please suggest how can I integrate the both or revert my changes if it is not possible to use them simultaneously?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抚笙 2024-11-12 19:21:43

我按照以下步骤安装 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

end

编辑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

I've followed these steps to install the gem:

rails generate devise:install

rails generate devise User

rails generate simple_private_messages:model User Message

Add this line (has_private_messages) to User Model:

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

end

Edit the routes.rb file, the order is important here, devise_for should be defined before the messages routes.

devise_for :users

resources :users do
    resources :messages do
        collection do
            post :delete_selected
        end
    end
end

If you want the scaffold:

rails generate simple_private_messages:scaffold User Message

And remember to uncomment this (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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文