use*_*793 1 post get ruby-on-rails
我正在使用搜索表单,并希望在rails表单上的ruby中使用GET请求.我用的是这样的东西
1)在视野中
form_tag(:action => "actionxyz", :method => "get")
Run Code Online (Sandbox Code Playgroud)
2)在路线中
get 'actionxyz', :controller => :controllerabc
Run Code Online (Sandbox Code Playgroud)
检查请求时,可以看到以下内容
<form accept-charset="UTF-8" action="/actionxyz?method=get" method="post"><div style="margin:0;padding:0;display:inline">
Run Code Online (Sandbox Code Playgroud)
我在网址中看到的更多,/actionxyz?method=get而不是我提供的搜索字符串.提供的搜索字符串显示在POST数据中.这是否意味着rails没有使用GET方法,或者我的解释错了.请澄清 ..
它将方法解释get为表单应该到达的路径的一部分,而不是其他选项form_tag.所以,你必须隔离它:
form_tag( {:action => "actionxyz"}, :method => "get") do
Run Code Online (Sandbox Code Playgroud)
要不就
form_tag url_path, method: :get do #where url_path is your route
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
244 次 |
| 最近记录: |