Hello, I must admit I’m new to rails (I actually come from the .net
world, but I’ve been meaning to expand for some time now)
I’m trying to create a user registration page (just getting my feet wet
really) and I’ve hit a wall. I’m pretty sure I’m doing this wrong, so I
need some straightening out
My db looks something like this:
UserAccount: Name, Email, Website, Status
Password: Key, Question, Answer
and my models:
class UserAccount < ActiveRecord::Base
validates_presence_of :Name, :Email
validates_uniqueness_of :Name, :Email
has_one :Password
accepts_nested_attributes_for :Password
end
class Password < ActiveRecord::Base
belongs_to :user_account
attr_accessor :password_confirmation
validates_confirmation_of :password
end
and the form that I’m trying to produce:
<% form_for(@user_account) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :Name %><br />
<%= f.text_field :Name %>
</p>
<% f.fields_for :Password do |fp| %>
<p>
<%= fp.label :Password %><br />
<%= fp.password_field :key %>
</p>
<p>
<%= fp.label :password_confirmation %><br />
<%= fp.password_field :password_confirmation %>
</p>
<% end %>
<p>
<%= f.label :Email %><br />
<%= f.text_field :Email %>
</p>
Optional
<%= f.label :Website %>
<%= f.text_field :Website %>
<%= f.label :Status %>
<%= f.text_area :Status %>
<%= f.submit 'Create' %>
<% end %>Now, as is, the browser doesn’t render the password at all. I think
that it is because “fields_for” is expecting a one-to-many relationship
and finding a one-to-one relationship (?), but if I take out the line
accepts_nested_attributes_for :Password I get the following error:
ActiveRecord::AssociationTypeMismatch in User accountsController#create
Password(#57105720) expected, got HashWithIndifferentAccess(#30298510)
I’m really stuck and I probably look really dumb, so that’s why i’m here
Thank you for ANY advice and sorry for my poor design/implementation