无法将form_tag方法设置为get

时间:2018-01-04 05:39:14

标签: ruby-on-rails slim-lang

我尝试使用这样的get方法发送一个form_tag

= form_tag search_offers_path, method: :get, class: 'sort-form form inputs-underline' do
              .sort-inputs
                .input-group.inputs-underline.min-width-150px.sort-input
                  = label_tag :sort_by, 'Sort by'
                  = select_tag :sort_by, options_for_select([["Sort by", ""], ["User level", "user_level"], ["Success rating", "user_average_overall_rating"]]), class: "form-control"
                .input-group.inputs-underline.min-width-150px.sort-input
                  = label_tag :sort_direction, 'Sort direction'
                  = select_tag :sort_direction, options_for_select([["Sort direction", ""], ["Ascending", "asc"], ["Descending", "desc"]]), class: "form-control"

但我不明白为什么它成为一个POST作为form_tag默认

Started POST "/offers/search" for 127.0.0.1 at 2018-01-04 12:35:18 +0700

ActionController::RoutingError (No route matches [POST] "/offers/search"):

任何人都有提示吗?

更新:我检查了基于反馈生成的HTML并看到data-remote = true(虽然我从未设置它,我也不想要ajax请求)。

1 个答案:

答案 0 :(得分:1)

<%= form_tag({}, {:method => :get, class: 'sort-form form inputs-underline'}) do %> 

试试这个。你绝对可以得到你的解决方案。