开发者

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)  开发者_如何学Python    {: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.


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 %>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜