form_for不会附加操作

时间:2017-04-28 13:22:21

标签: ruby-on-rails ruby-on-rails-5

我有 html.erb rails代码:

<%= form_for(:dash_action, method: :post, url: {controller: 'brokers', action: 'dashboard'}) do |f| %>
  <%= f.submit("Suchen", class: "btn btn-primary", id: "change_status") %>    
<% end %>

当我检查生成的HTML代码时,我会看到表单元素

<form action="/brokers" accept-charset="UTF-8" method="post">

但我希望将此视为行动: action =“/ brokers / dashboard”

出了什么问题?

............................................... .......

这里所有的经纪人都与路线有关:

  get 'brokers/login_page'
  get 'brokers', to: 'brokers#dashboard'
  post 'brokers/dashboard', to: 'brokers#dashboard'
  post 'brokers/eval_login', to: 'brokers#eval_login'
  get 'brokers/logout'
  get 'brokers/edit_order_now'

当我做url_for(controller: 'brokers', action: 'dashboard')时 我只得到: /中间商

2 个答案:

答案 0 :(得分:1)

您可以在form_for标记上使用绝对路线,您的路线应该是dashboard_brokers_path

<%= form_for(:dash_action, url: dashboard_brokers_path, method: :post) do |f| %>
   <%= f.submit("Suchen", class: "btn btn-primary", id: "change_status") %>    
<% end %>

答案 1 :(得分:0)

尝试以下代码:

<%= form_for(:dash_action, url: "/brokers/dashboard") do |f| %>
  <%= f.submit("Suchen", class: "btn btn-primary", id: "change_status") %>    
<% end %>