我在视图页面中有一个复选框:
<table>
<tr>
<td>
<% @user_profession.each do |p| %>
<% if !p.Designation.blank? and p.Private? == "1" %>
<%= check_box(:ChkBx_Profession, {:id => "ChkBx_Profession",:value => "Profession"},true) %>
<%= label(:lb_Profession, "Profession") %>
<% else %>
<%= check_box(:ChkBx_Profession,{:id => "ChkBx_Profession",:value => "Profession"}) %>
<%= label(:lb_Profession, "Profession") %>
<% end %>
<% end %>
</td>
</tr>
</table>
以下是我的控制器页面
if params[:ChkBx_Profession] == "1"
@blah = params[:ChkBx_Profession]
@publicprofession = params[:ChkBx_Profession]
Profession.delete_all(:UserID => current_user.id)
if !params[:tf_designation].blank?
@desig = params[:tf_designation]
@comp = params[:tf_company]
@fromdesigcom = params[:tf_fromdesignation]
@todesigcom = params[:tf_todesignation]
@public_profession = @publicprofession
@Profession = Profession.new( :UserID => current_user.id, :Designation => @desig, :Company => @comp, :Job_From => @fromdesigcom, :Job_To => @todesigcom, :Private? => @publicprofession )
@Profession.save
end
end
我希望获得复选框值意味着如果复选框被选中它会得到1而如果取消选中复选框则会得到0但是它会像{"{:id=>\"ChkBx_Profession\", :value=>\"Profession\"}"=>"1"}
那样得到。请帮我等你的回复。
感谢
答案 0 :(得分:0)
check_box上的第二个属性是:value属性。尝试在chec_box名称和选项之间放置空双引号:
<%= check_box(:YourCheckName, "",{Your Options}) %>