我的索引中有一个表单,该表单发布到与我自己创建的操作对应的url中。我的索引是“ / instructions”,提交表单后,我想将表单重定向为“ / instructions / quick_run”。
目前,我有:
instructions_controller.rb
class InstructionsController < ApplicationController
def index
@instruction = Instruction.all
end
def quick_run
@analysis_options = params
end
end
index.html.slim
= form_with url: "/instructions/quick_run" do |form|
p = form.file_field :text_file, as: :file, accept: '.txt'
p = form.submit
routes.rb
resources :instructions, only: [:index,:new,:edit,:destroy] do
collection do
post 'quick_run'
get 'quick_run'
end
end
点击提交后,我可以看到启动的POST“ / instructions / quick_run”以及作为参数传递的文件输入,但是我没有被重定向到“ / instructions / quick_run”。我还收到有关指令/quick_run.html.slim正在渲染的通知,但是它没有显示,并且网址仍然是“ / instructions”
答案 0 :(得分:1)
您似乎正在使用Rails 5.x,对吗?
默认情况下,Rails 5假定您将使用Ajax(javascript)提交请求,并且不进行本地发布事件。参见:http://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html#form-with
要更改此行为,请使用local: true
= form_with url: "/instructions/quick_run", local: true do |form|
p = form.file_field :text_file, as: :file, accept: '.txt'
p = form.submit