I am using rails 3.1 and ruby 1.9.3 for my application. And the issue is, I am getting "Can't mass-assign protected attributes" while saving the details.
I have User model as:
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
And Profile model as:
class Profile < ActiveRecord::Base
belongs_to :user
end
I am having few fields in "User" model and personal data like first_name, last_name and etc in "Profile" model. And I am trying to get all the required data by customizing the devise signup form as follows:
<%= 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>
Can anyone please tell me where I am going wrong.