我有一个单选按钮这个Ruby代码在我的用户new
形式:属性没有被设置
<%= f.fields_for :profile, Profile.new do |t| %>
<div class ="field">
<%= t.label :type, "Are you an artist or listener?" %><br />
<p> Artist: <%= t.radio_button :type, "artist" %></p>
<p> Listener: <%= t.radio_button :type, "listener" %></p>
</div>
<% end %>
我想设置我的剖面模型的type
属性。但是,类型未设置,默认为nil
。我想在我的个人资料控制器创建这个create
方法,但它没有工作:
def create
@profile = Profile.find(params[:id])
if params[:profile_attributes][:type] == "artist"
@profile.type = "artist"
elsif params[:profile_attributes][:type] == "listener"
@profile.type = "listener"
end
end
我怎样才能得到type
设置为“艺术家”或“监听器”是否正确?
UPDATE:
我得到这个错误:WARNING: Can't mass-assign protected attributes: type
您是否使用STI? – 2011-03-27 22:21:04
是的,我正在使用STI – 2011-03-27 22:22:25