我想创建一个表单,我将有2个单选按钮。一个用于公共'另一方面是私人'。
我的项目中有一个用户模型,我有隐私字段,它是布尔值,默认值为true(在我的情况下是' public')。
我的表单中有更新按钮。我想提交表单,因此想要更新用户模型中的值。然后,如果我每次访问编辑页面时都应该选择相应的单选按钮。
这是我的表格
= form_tag "/users/abc" do
%p.heading We Respect Your Privacy
.privacy
%input#r1{:name => "privacy", :type => "radio", :value => 0}
%label.privacyLabel{:for => "r1"}
%span>
Friends Only
%p
TraveLibro enables you to save your travel memories and share them with your friends. While other TraveLibro users
can see your itineraries, only your friends on TraveLibro can view your personal pictures.
%br
%p Now you can upload all your captured memories without ever having to be concerned about your privacy.
.privacy
%input#r2{:name => "privacy", :type => "radio", :value => 1}
%label.privacyLabel{:for => "r2"}
%span>
Everyone
%p
Want to share your travel tales with the world. With an open profile TraveLibro users can view the itineraries
you have created and the pictures that complete those memories.
.privacyUpdate
%a{:href => "javascript:void(0);"}
%input.privacyUpdateBtn{:type => "submit", :value => "update"}/
这是我的控制器动作
def abc
current_user.update_column('privacy', params[:privacy] == 0 ? 0 : 1)
redirect_to :back
end
但它不起作用
答案 0 :(得分:0)
试试这个:
def abc
current_user.update_column('privacy', params[:privacy].to_i == 0 ? 0 : 1)
redirect_to :back
end