RoR...当我使用单选按钮时,我的脚手架表没有填满
我有一个问题,我制作了一个脚手架,生成表“需求”,我希望用户在编辑中填充表的字段以及使用选择框和单选按钮的新需求。选择框和单选按钮出现在资源管理器中,但是当我选择一个选项或一个按钮时,选择的该值不会反映在数据库中。我使用的代码是下一个:(如您所见,我使用了由脚手架生成的原始 cicle f.label(:notif_card) 和 f.text_field(:notif_card) ,但我删除了最后一个并使用了中的选择框本案。)
<%= f.label :notif_card %><br />
<% value = { "Good" => 0, "In Progress" => 1, "Denied" => 2 }%>
<%= select( @requirement, :notif_card , value) %>
<% if value == 1 %>
<% @requirement.notif_card = 1 %>
<%end%>
我只想删除该文本字段并将其替换为选择框!你能做的一切我都会非常感激!如果除了我正在使用的代码之外,模型或控制器中还需要某些内容,请告诉我。感谢您的帮助!
I have a problem, i made a scaffold, generating the table "requirements", i want the user to fill the fields of the table in the edit and the new requirement with select boxes and radio buttons. The select box and the radio buttons appear in the explorer but when i select one option or one button, that value selected it's not reflected in the db. The code im using its the next: (As you can see i used the original cicle f.label(:notif_card) and f.text_field(:notif_card) generated by the scaffold, but i deleted the last one and used the select box in this case.)
<%= f.label :notif_card %><br />
<% value = { "Good" => 0, "In Progress" => 1, "Denied" => 2 }%>
<%= select( @requirement, :notif_card , value) %>
<% if value == 1 %>
<% @requirement.notif_card = 1 %>
<%end%>
I just want to delete that text_field and replace it with a select box! Everything you can do i will appreciate it alot! If something needs to be in the model or in the controller besides the code that i'm using please let me know. Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想使用单选按钮将值从表单存储到数据库,您可以使用单选按钮。
语法如下所示,
将使用单选按钮将值存储在数据库中。
如果你想使用同样的复选框方法,你可以使用,但它是布尔方法。所以在开始生成脚手架时需要将其声明为布尔值。
if you want to use the radio buttons for storing values from form to DB you can use the radio buttons..
the syntax will be like
this will store values on the database by using radio buttons.
if you want to use check box method for the same, you can use but it is of Boolean method.so needs to be declared as boolean when start generating scaffolding it.