开发者

Nested form with devise

开发者 https://www.devze.com 2023-03-07 01:39 出处:网络
This is my sign up form: <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>

This is my sign up form:

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>

  <p><%= f.label :email %><br />
  <%= f.email_field :email %></p>

  <p><%= f.label :password %><br />
  <%= f.password_field :password %></p>

  <p><%= f.label :password_confirmation开发者_StackOverflow社区 %><br />
  <%= f.password_field :password_confirmation %></p>

  <%= f.fields_for :profile do |t| %>
     <div class ="field">
        <%= t.label :type, "Are you an artist or listener?" %><br />
        <p> Artist: <%= t.radio_button :type, "Profile::Artist", :id => "artist_button" %></p>
        <p> Listener: <%= t.radio_button :type, "Profile::Listener", :id => "listener_button" %></p>
      </div>
  <% end %>

  <p><%= f.submit "Sign up", :id => "new_user_submit" %></p>
<% end %>

I also have this in my user model:

 accepts_nested_attributes_for :profile

However the problem is that the radio buttons that is nested in the form is not even appearing on the page. How can I fix this?


You probably need to build an empty profile object on your User object (or whatever it's called) first:

@user.build_profile
0

精彩评论

暂无评论...
验证码 换一张
取 消