表单标签和查询

时间:2015-07-19 12:11:01

标签: mysql ruby-on-rails ruby

我一直在研究一个问题,我觉得我的解决方案应该是正确的,但它一直给我“冻结;结束”错误。

我正在进行餐馆搜索,我试图让用户设置参数以帮助缩小他们想要的餐馆。

以下是我的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 home中的welcome_controller中:

@my_search = Restaurant.joins(:inspection).where(cuisine: params[:cuisine], zipcode: params[:zipcode], totalscore: params[:lower..:higher])

为什么我收到错误?

感谢大家的帮助到目前为止,我认为现在一切都在一起

1 个答案:

答案 0 :(得分:0)

请更改此

 @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:"