form_tag始终重定向到同一个控制器#action(static_pages #index)

时间:2017-02-15 20:04:59

标签: ruby-on-rails

这个问题让我发疯了。

我在application.html.erb中有两个表单。他们应该触发pedidos #index和pedidos #excel actions,但无论如何都会触发static_pages #index。我没有收到任何错误消息。如果我手动编写url / pedidos然后我提交,则第一种形式有效。

  

的routes.rb

root 'static_pages#index'
get 'pedidos', to: 'pedidos#index'
get 'excel', to: 'pedidos#excel'
  

application.html.erb

<%=form_tag pedidos_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search], placeholder: 'Búsqueda por OSCAR' %>
<%= submit_tag "Búsqueda", :name => nil, class: 'btn btn-info' %>
<% end %>

另一种形式:

<%=form_tag excel_path(format: :xlsx) , :method => 'get' do |f| %>
<%=select_date Date.today, prefix: :fecha %>
<%=submit_tag "Generar EXCEL de entregas", :name => nil, class: 'btn btn-info btn-sm' %>
<% end %>

最后这就是路线的样子:

pedidos_path    GET /pedidos(.:format)  pedidos#index

excel_path  GET /excel(.:format)    pedidos#excel

root_path   GET /   static_pages#index

1 个答案:

答案 0 :(得分:1)

最后结果证明这是一个HTML问题,我将表单嵌套在Bootstrap导航栏表单代码中。

这种方式有效:

<div class="form-group">
     <%= form_for '', url: {controller: 'pedidos', action: 'index' }, method: :get, class: 'navbar-form navbar-left' do |f| %>
     <%= text_field_tag :search, params[:search], placeholder: 'Búsqueda por OSCAR' %>
     <%= submit_tag "Búsqueda", :name => nil, class: 'btn btn-info' %>
     <% end %>
</div>
相关问题