Mongoid将用户信息添加到数据库

时间:2013-12-03 02:28:53

标签: ruby-on-rails ruby devise mongoid

我正在使用带有mongoid和设计宝石的rails 4。我在user.rb中添加了一些字段。

class User
  include Mongoid::Document
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

  field :profile_name,      :type => String
  field :type,              :type => String
  field :gender,            :type => String
  field :location,          :type => String
  field :about,             :type => String
  ...
end

我还编辑了注册和编辑表格:

<div><%= f.label :profile_name %><br />
<%= f.text_field :profile_name, :autofocus => true %></div>

<div><%= f.label :type %><br />
<%= f.text_field :type, :autofocus => true %></div>

<div><%= f.label :gender %><br />
<%= f.select :gender, options_for_select(%w[Male Female]), :prompt => "Select your gender" %></div>

但它只保存标准信息:电子邮件和密码。我想添加强_params,但我的项目文件夹中没有user_controller.rb。

No user_controller.rb

即使我添加了服务器,服务器也会崩溃并且无法启动:

gem 'strong_parameters'
宝石文件中的

。我不知道我的问题是什么。否则,我可以添加帖子并将它们存储好。

1 个答案:

答案 0 :(得分:1)

首先,请确保通过Rails 4完全阅读Devise。您需要在application_controller.rb

中设置强大的参数

Rails 4默认使用strong_params,因此无需尝试安装它。您需要根据application_controller.rb

中的方式添加所需的属性

就像七只猫所说:

https://github.com/plataformatec/devise

阅读文档并了解设计是如何工作的,如果你真的不明白发生了什么,它会引起很多痛苦。

我建议首先尝试使用本教程从头开始构建系统:

http://ruby.railstutorial.org/ruby-on-rails-tutorial-book

他从头开始经历一个完整的用户系统。

相关问题