这在我的索引视图中,我想访问类似的: false/true参数
<%= link_to like_theory_path(theory, like: true), method: :post do %>
<i class="glyphicon glyphicon-thumbs-up"></i>
 
<%= theory.thumbs_up_total %>
<% end %>
 
 
<%= link_to like_theory_path(theory, like: false), method: :post do %>
<i class="glyphicon glyphicon-thumbs-down"></i>
 
<%= theory.thumbs_down_total %>
<% end %>这个在我的控制器里
if :like
if like.like
like.delete
else
like.delete
like = Like.create(like: params[:like], theorist: current_user, theory: @theory)
like.valid?
end
else
binding.pry
if like.like
like.delete
like = Like.create(like: params[:like], theorist: current_user, theory: @theory)
like.valid?
else
like.delete
end
end因此,不管是真是假,它都不会击中the语句。
我是否正确地使用了这个,或者它在技术上根本不是一个参数?
发布于 2015-08-18 00:43:54
link_to助手通过params哈希传递参数。params哈希包含类型为string的值,因此不能传递布尔值。
然而,您可以做的是传递布尔值的其他表示形式,如"1“或"0",或"true”或"false“,并创建与控制器方法中传递的值对应的实际布尔值。
您可能希望创建一个虚拟属性,这样字符串like就不会与模型的布尔like字段发生冲突。
https://stackoverflow.com/questions/32061705
复制相似问题