submitting params with form_tag to update method gives undefined route error

I have a form like this:

= form_tag item_path(@item) do
  # some inputs

This gives following HTML:

<form method="post" action="/items/1" accept-charset="UTF-8">
  <!-- some inputs -->

When I submit it - I get a following error:

No route matches [POST] "/items/1"

However when I use SimpleForm for the same item - HTML is almost the same and it works:

# code:
= simple_form_for @item do |f|
# output:
<form id="edit_item_1" novalidate="novalidate" method="post" action="/items/1" accept-charset="UTF-8">

Do you see any mistakes in my code?

How do I make sure that my form_tag submits params to the item update method?


I am not sure why simple_form_for works. But normally Rails form_tag methods generates form with http method POST.

<form method="post"

So in your case if you want to submit the form to update method then http method should be PUT. You can explicitly specify the http method in rails form_tag.

form_tag item_path(@item), :method => :put do |f|

Normally people will always prepare form_for instead of form_tag and they will reuse the form template for create and update. Because form_for will set correct http method based on record status.If the record is new it will set the http method to POST else PUT.

Did you define the path in your routes.rb file?

resources :items, only: :create

or post "/items/:id" => "items#create"

I suggest the first one

Need Your Help

hatched rectangle patches without edges in matplotlib

matplotlib patch hatchstyle

When trying to add a rectangle patch with a hatch pattern to a plot it seems that it is impossible to set the keyword argument edgecolor to 'none' when also specifying a hatch value.

Error is loading the jars

java classpath ejb

i`m getting NoClassDefintion found error in my application even though i had the associated jars in my lin folder of my ear the error is

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.