开发者

RoR no route matches

I have this code in my routes:

   controller :active_car do
    put 'switch_car' => :update
    get 'switch_car' => :edit
   end

This is my code in on my edit page.

    <% form_tag('switch_car', :method => :put) do%>
<div class="field">
    <label for="car_info_id">Car Name:</label>
    <%= select("", "car_info_id", @available_cars.collect {|v| [v.name, v.id]})%>
</div>
<div>
    <%= submit_tag "Switch Car" %>
</div>
<% end %>

When I click submit I get the following routing error.

No route matches "/switch_car" with the url pointing to http://localhost:3000/switch_car?method=put

The get is working just fine as I end the url with switch_car I get my page to edit. For some reason the put definition is not working.

After changing method to second argument it just doesn't work. It seems to have post as the method still instead of put. Here is generated HTML

<form accept-charset="UTF-8" action="switch_car" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="_method" type="hid开发者_运维百科den" value="put" />


:method belongs to the "options" hash, which is form_tag's second argument, not the first.

http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-form_tag

Please inspect the html generated by that tag and post it here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜