Hello, Im noob in Rails and I have problems with the relationship into
my model User and Profile. I want to create both models with only one
form but i dont know as. I can see the fields of profile but went y
press create only create user. Thanks for help. This is my form.

<%= nested_form_for(@user) do |f| %>
    <% if @user.errors.any? %>
        <div id="error_explanation">
          <h2><%= pluralize(@user.errors.count, "error") %> prohibited
this user from being saved:</h2>

          <ul>
            <% @user.errors.full_messages.each do |message| %>
                <li><%= message %></li>
            <% end %>
          </ul>
        </div>
    <% end %>

    <div class="field">
      <%= f.label :user_name %><br>
      <%= f.text_field :user_name %>
    </div>
    <div class="field">
      <%= f.label :email %><br>
      <%= f.text_field :email %>
    </div>
    <div class="field">
      <%= f.label :password %></br>
      <%= f.password_field :password %>
    </div>

    <div class="field">
      <%= f.label :password_confirmation %></br>
      <%= f.password_field :password_confirmation %>
    </div>

    <%= f.fields_for :profiles do |f1| %>
        <div class="field">
          <%= f1.label :name %><br>
          <%= f1.text_field :name %>
        </div>
        <div class="field">
          <%= f1.label :last_name %><br>
          <%= f1.text_field :last_name %>
        </div>
        <div class="field">
          <%= f1.label :birthday %><br>
          <%= f1.datetime_select :birthday %>
        </div>
        <div class="field">
          <%= f1.label :avatar %>
          <%= f1.file_field :avatar %>
        </div>
    <% end %>
    <div class="actions">
      <%= f.submit %>
    </div>
<% end %>
 And this is my UserController

  def user_params
    params.require(:user).permit(:user_name, :email, :password,
:password_confirmation, profile_attributes: [:name, :last_name, :avatar,
:birthday])
  end
end


Thnks

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/37bc51af3a1aaf4b7fdd7f78fa17c04e%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to