Sven Kirsten
Sven Kirsten

Reputation: 518

form_for does not append the action

I have this html.erb rails code :

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

When I check the generated HTML code, I see this for the form element :

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

But I expect to see this as action: action="/brokers/dashboard"

Whats going wrong ?

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

Here all brokers relates routes:

  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'

Also when I do a url_for(controller: 'brokers', action: 'dashboard') I got only : /brokers

Upvotes: 0

Views: 25

Answers (2)

Rokibul Hasan
Rokibul Hasan

Reputation: 4156

You can use absolute route on the form_for tag, your route should be like this 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 %>

Upvotes: 1

puneet18
puneet18

Reputation: 4427

try below code:

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

Upvotes: 0

Related Questions