user807157
user807157

Reputation: 23

Rails 3 update routing error

I am having trouble with my routing in a Rails application.

My routing file has:

resources :translations

Which should create several routes, including update.

Doing a rake routes shows the update route is there:

PUT    /translations/:id(.:format)      {:action=>"update", :controller=>"translations"}

However, when I use the following code to link to the update:

<% form_tag( {:controller => "translations", :action => "update"}, {:multipart => true}) do %>
  <p><%= label_tag "upload", translate("UI_TEXT_FORM_SELECT_AUDIO_FILE") %>:
  <%= file_field_tag "upload" %></p>
  <%= submit_tag translate("UI_TEXT_FORM_SAVE") %>
<% end %>

I get this result:

Routing Error
No route matches "/translations/10"

Any help would be appreciated.

Upvotes: 2

Views: 784

Answers (2)

Christian Fazzini
Christian Fazzini

Reputation: 19723

Try including the :put method. For example:

<%= form_tag({:controller => "translations", :action => "update"}, :html => {:method => :put, :multipart => true}) do %>

Second, you should have an alias for the route. If its a RESTFUL route, which it looks like it is. You could do something like (below), instead of indicating which controller and action it should submit to.

<%= form_for(@transaction, :url => transaction_path, :html => {:method => :put, :multipart => true}) do %>

For your reference.

Upvotes: 0

David Sulc
David Sulc

Reputation: 25994

It's probably looking for a route with POST. Try adding :method => :put in the options hash:

<% form_tag( {:controller => "translations", :action => "update"}, {:multipart => true, :method => :put}) do %>

Upvotes: 2

Related Questions