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 %>
<fieldset>
<legend>Required</legend>
<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>
</fieldset>
<fieldset>
<legend>Optional</legend>
<p>
<%= f.label :Website %><br />
<%= f.text_field :Website %>
</p>
<p>
<%= f.label :Status %><br />
<%= f.text_area :Status %>
</p>
</fieldset>
<p>
<%= f.submit ''Create'' %>
</p>
<% 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
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.