我有这种注册用于与色器件:两个形式的值不被保存
<%= 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 %>
然后,我有一些JQuery的那个插入动态字段:
$("#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>');
});
然而,type
属性,该属性是嵌套在用户表单中,并且动态插入的name
属性不会保存到数据库中。值被输入为空。
这是为什么?我怎样才能解决这个问题?
UPDATE:
name属性不attr_accessible
,并且是导致它不会被保存到数据库。但是,嵌套在用户表单中的type属性为attr_accessible
,但仍未保存到数据库中。
实际提交了什么?你在开发日志中看到什么参数? – Roman 2011-05-17 22:29:42
他们是'attr_accessible'吗? – apneadiving 2011-05-17 22:30:43
它在参数中,但我不认为它们是'attr_accessible' ...会输入配置文件模型中? – 2011-05-17 22:32:10