目标是通过特定的链接传递特定的布尔值(true或false)。Rails 4:在新动作上传递布尔值
我已经试过:
<%= link_to "new test", new_test_path(:crazy => true) %>
网址:/测试/新疯狂=真
视图
<div class="field">
<%= f.radio_button :crazy, true %> True
<%= f.radio_button :crazy, false %> False
</div>
static_pages_controller
?def home
@test = Test.new
...
end
但是当我单击该链接时没有选中单选按钮。
您需要在控制器中将该属性的值设置为true。如果它是'true',则第一个按钮将被检查。如果它是'假',第二个按钮将被检查。这可能是'无'。 – Swards 2014-09-13 14:58:56
你可以写一个答案,看看如何实际做到这一点?我试着用[:crazy =>'true']在test_params中设置值,但它仍然不起作用。 – 2014-09-13 15:12:39