我已经研究了一段时间的问题,我觉得我的解决方案应该是正确的,但它一直给我“卡住;结束”错误。
我正在搜索餐厅,我试图让用户设置参数以帮助缩小他们想要的餐厅的范围。
下面是我的html代码:
<!DOCTYPE html>
<html>
<body>
<%= form_tag home_path do %>
<%= label_tag(:cuisine, "Cuisine:" %>
<%= text_field_tag (:cuisine) %>
<%= label_tag(:zipcode, "Zipcode:" %>
<%= text_field_tag (:zipcode) %>
<%= label_tag(:lower, "lowerScore:" %>
<%= text_field_tag (:lower) %>
<%= label_tag(:higher, "higherScore:" %>
<%= text_field_tag (:higher) %>
<%= submit_tag("Search") %>
<% end %>
<% @my_search.each do|search| %>
<%= search.name %>
<% end %>
</body>
</html>
在 def 主页中我的 welcomes_controller 中:
@my_search = Restaurant.joins(:inspection).where(cuisine: params[:cuisine], zipcode: params[:zipcode], totalscore: params[:lower..:higher])
为什么我会收到错误消息?
感谢大家到目前为止的帮助,我想现在一切都在一起了
最佳答案
请改变这个
@my_search = Restaurant.joins(:inspection).where(cuisine: params[:cuisine}, zipcode: params[:zipcode], totalscore: params[:lower..:higher])
对此
@my_search = Restaurant.joins(:inspection).where(cuisine: params[:cuisine], zipcode: params[:zipcode], totalscore: params[:lower..:higher])
其次,这个label_tag好像不太对。这在哪里结束(
例如改变这个
label_tag(:cuisine, "Cuisine:"
对此
label_tag :cuisine, "Cuisine:"
关于mysql - 表单标签和查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31501045/