Reputation: 1177
I'm and usings devise for my authentication and would like to keep the details of my users in a separate model called profile. Profile contains information like first and last name. I want to be able to have a single sign up form that will be able to have all this information entered.
This is my form
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= render 'shared/error_messages' %>
<% fields_for :profile do |fa| %>
<%= fa.label :first_name %>
<%= fa.text_field :first_name %>
<%= fa.label :last_name %>
<%= fa.text_field :last_name %>
<% end %>
<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>
<div><%= f.submit "Sign up" %></div>
<% end %>
This in my user.rb model
has_one :profile
accepts_nested_attributes_for :profile
When I submit the from it doesn't save the first and last name to the database
Upvotes: 2
Views: 2309
Reputation: 1177
After much searching around, this was the simplest answer to my question. Although I'm not sure this the rails way of doing things
Profile model for Devise users?
Upvotes: 1