下午全部,
我正在尝试在我的rails应用程序中添加一个过滤器,但是当我处理下面的内容时,它会重定向到提交时的创建操作,我无法弄清楚它为什么会传递给此操作:
jobs_controller.rb
def index
@jobs = Job.all
@show_sub_nav = true
@lang = Job.find_by_sql("SELECT languages FROM jobs GROUP BY languages").map &:languages
@list = params[:languages].blank? ? Job.all : Job.find_all_by_category(params[:languages])
end
我的观点
<%= form_tag(jobs_path :method => 'get', :action => 'index') do %>
<%= select_tag "languages", options_for_select(@lang) %>
<%= submit_tag "Filter" %>
<% end %>
我正在使用不同的选项来玩form_for(),但它似乎没有任何区别,这里是登录点击:
Started POST "/jobs?method=get" for 127.0.0.1 at 2013-12-16 19:35:54 +0000
Processing by JobsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"p34KrqtWpFr5xCAB+leP3YkVbJjLpDKix4BJDUZquAg=", "languages"=>"Ratke-Beatty", "commit"=>"Filter", "method"=>"get"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
(0.1ms) begin transaction
(0.1ms) rollback transaction
Rendered jobs/_subregion_select.html.erb (0.1ms)
Rendered jobs/_form.html.erb (38.7ms)
Rendered jobs/new.html.erb within layouts/application (39.9ms)
Rendered layouts/_navbar.html.erb (0.5ms)
Completed 200 OK in 75ms (Views: 54.2ms | ActiveRecord: 0.8ms)
答案 0 :(得分:0)
重定向,因为您将http类型设置为GET::method => 'get'
。
通常,形成POST数据,因此您需要:method => 'post'
,或者如果您正在遵循restful路由设计,则无需指定:method
,因为rails足够聪明。
答案 1 :(得分:0)
解决了以下问题:
<%= form_tag({ :action => "index"}, { :method => "get"}) do %>
似乎工作并给我正确的输出。