I have an Account model with the following :
has_one :primary_user, :class_name => "User", :conditions => "role = 'primary_user'"
So @account.primary_user looks for a user with a role of primary_user.
When creating a new account, I want to be able to create a new primary_user. What is the “Rails way” to do that ?
Do I need to create a primary_user= method?
Here is my create form ..
<%= semantic_form_for @account do |f| %>
<%= f.input :account_name %>
<%= f.semantic_fields_for :primary_user do |user| %>
<%= user.input :email %>
<% end %>
<% end %>
If I submit this form I get
ActiveRecord::AssociationTypeMismatch (User(#2159789500) expected, got ActiveSupport::HashWithIndifferentAccess(#2159703820)):
Thanks
Little cleaner:
Then straight solution:
But I suggest you to add this into new action in controller