"new", :controller=>"li..." /> "new", :controller=>"li..." /> "new", :controller=>"li..."/>

How do I update create route from rails 3 to 4

41 views Asked by At

I have a form tag which is seen below, when I try to run the page I get the error: No route matches {:action=>"create", :type=>"new", :controller=>"lists"}

  <%= form_for @list, :url => {:action => "create", :type => "new"}, :html => {:multipart => true,:role=>"form"} do |f| %>

In my routes file i have a line-- resources :lists I thought the line above in the routes file is supposed to create correct routes for me.

Can someone tell me what I am doing wrong?

2

There are 2 answers

2
Mac On BEST ANSWER

The url option needs a controller if you're going to format things this way... and there isn't a type option in url_for... so it should probably look like this:

<%= form_for @list, :url => {:controller => 'lists', :action => "create"}, :html => {:multipart => true,:role=>"form"} do |f| %>

Or without the hash rockets:

<%= form_for @list, url: { controller: 'lists', action: "create" }, html: { multipart: true, role: "form"} do |f| %>
0
splendidthoughts On

check the method, create must be sent via POST as

<%= form_for @list, as: :list :url => lists_path, method: :post do |f| %>