Ruby on rails 3.1 Can';t使用设计注册表分配受保护属性问题

Ruby on rails 3.1 Can';t使用设计注册表分配受保护属性问题,ruby-on-rails-3.1,devise,ruby-1.9.3,Ruby On Rails 3.1,Devise,Ruby 1.9.3,我的应用程序使用rails 3.1和ruby 1.9.3。 问题是,我在保存详细信息时遇到“无法批量分配受保护的属性” 我的用户模型为: class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise

我的应用程序使用rails 3.1和ruby 1.9.3。 问题是,我在保存详细信息时遇到“无法批量分配受保护的属性”

我的用户模型为:

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

has_one :profile
accepts_nested_attributes_for :profile

attr_accessible :email, :password, :password_confirmation, :remember_me, :profile_attributes, :first_name, :last_name

end
class Profile < ActiveRecord::Base

belongs_to :user

end
class用户
配置文件模型如下所示:

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

has_one :profile
accepts_nested_attributes_for :profile

attr_accessible :email, :password, :password_confirmation, :remember_me, :profile_attributes, :first_name, :last_name

end
class Profile < ActiveRecord::Base

belongs_to :user

end
类配置文件
我在“用户”模型中有几个字段,在“个人资料”模型中有个人数据,如名字、姓氏等。我正试图通过定制Desive注册表格获取所有所需数据,如下所示:

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>

<div><%= f.label :email %><br />
<%= f.email_field :email %></div>

<div><%= f.label :password %><br />
<%= f.password_field :password %></div>

<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>


<%= f.fields_for :profile do |builder| %>
    <div><%= builder.label :first_name, "First Name" %><br />
    <%= builder.text_field :first_name %></div>
    <div><%= builder.label :last_name, "Last Name" %><br />
    <%= builder.text_field :last_name %></div>
<% end %>


<div><%= f.submit "Sign up" %></div>
resource_name,:url=>registration_path(resource_name))do | f |%>






谁能告诉我哪里出了问题。

如果
名字
姓氏
字段属于配置文件模型,那么您应该在配置文件模型本身中将其称为
属性

您的配置文件模型应该如下所示

class Profile < ActiveRecord::Base
belongs_to :user
attribute_accessible :first_name, :last_name
end
类配置文件
配置文件属性是什么?您不应该创建一个配置文件,然后在事务中分配给用户吗?从这里开始,我想你可能误导了自己,把个人资料的属性放在用户的属性中是不可能的!