I have this signup for with devise:
<%= 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 %><br />
<%= f.password_field :password_confirmation %></p>
<%= f.fields_for :profile, resource.build_profile do |t| %>
<div class ="field">
<%= t.label :type, "Are you an artist or listener?" %><br />
<div>Artist: <%= t.radio_button :type, "Profile::Artist", :id => "artist_button" %></div>
<div>Listener: <%= t.radio_button :type, "Profile::Listener", :id => "listener_button" %></div>
</div>
<% end %>
<p class="before"><%= f.submit "Sign up", :id => "new_user_submit" %></p>
<% end %>
Then I have some JQuery that inserts a field dynamically:
$("#artist_button").click(function() {
if ($('input#user_name').parent().hasClass('field')){
$('input#user_name').parent().remove();
}
$(".before").before('<div class="field"><label for="user_name">Artist or Band/Group Name</label><br><input id="user_name" name="user[name]" size="30" type="text"></div>');
});
However, the type attribute that is nested in the user form and the name attribute that is inserted dynamically are not being saved to the database. The values are being entered as null.
Why is this? How can I fix this?
UPDATE:
The name attribute was not attr_accessible and that was causing it to not be saved to the db. However, the type attribute, which is nested inside the user form, is attr_accessible but is still not being saved to the db.
Try putting in your User Model:
along with the rest of devises
attr_accessible(email,remeber_me,etc), do not delete what you have!