Routing problem

In my app i have word model, words_controller and want create new action for word model. I create new method 'test' in words_controller, and adds: resources :words do     member do       put 'test'     end   end in routes.rb my rake routes output: test_word PUT /words/:id/test(.:format) {:action=>"test", :controller=>"words"}        words GET /words(.:format) {:action=>"index", :controller=>"words"}              POST /words(.:format) {:action=>"create", :controller=>"words"}     new_word GET /words/new(.:format) {:action=>"new", :controller=>"words"}    edit_word GET /words/:id/edit(.:format) {:action=>"edit", :controller=>"words"}         word GET /words/:id(.:format) {:action=>"show", :controller=>"words"}              PUT /words/:id(.:format) {:action=>"update", :controller=>"words"}              DELETE /words/:id(.:format) {:action=>"destroy", :controller=>"words"}      session POST /session(.:format) {:action=>"create", :controller=>"sessions"} new_session GET /session/new(.:format) {:action=>"new", :controller=>"sessions"} edit_session GET /session/edit(.:format) {:action=>"edit", :controller=>"sessions"}              GET /session(.:format) {:action=>"show", :controller=>"sessions"}              PUT /session(.:format) {:action=>"update", :controller=>"sessions"}              DELETE /session(.:format) {:action=>"destroy", :controller=>"sessions"}        login /login(.:format) {:action=>"new", :controller=>"sessions"}       logout /logout(.:format) {:action=>"destroy", :controller=>"sessions"}         root /(.:format) {:action=>"index", :controller=>"words"} But when i'm going to something like http://localhost:3000/words/22/test i'm get error Routing Error

No route matches "/words/22/test"

Why? what am I doing wrong?

In my app i have word model, words_controller and want create new

action for word model.

I create new method ‘test’ in words_controller, and adds:

resources :words do

member do

  put 'test'

end

end

in routes.rb For Rails 3, replace the above route with match “/words/:id/test” => “words#test”

In my app i have word model, words_controller and want create new

action for word model.

I create new method ‘test’ in words_controller, and adds:

resources :words do

member do

  put 'test'

end

end

in routes.rb

my rake routes output:

test_word PUT /words/:id/test(.:format) {:action=>“test”,

:controller=>“words”}

   words GET    /words(.:format)          {:action=>"index",

:controller=>“words”}

         POST   /words(.:format)          {:action=>"create",

:controller=>“words”}

new_word GET    /words/new(.:format)      {:action=>"new",

:controller=>“words”}

edit_word GET /words/:id/edit(.:format) {:action=>“edit”,

:controller=>“words”}

    word GET    /words/:id(.:format)      {:action=>"show",

:controller=>“words”}

         PUT    /words/:id(.:format)      {:action=>"update",

:controller=>“words”}

         DELETE /words/:id(.:format)      {:action=>"destroy",

:controller=>“words”}

 session POST   /session(.:format)        {:action=>"create",

:controller=>“sessions”}

new_session GET /session/new(.:format) {:action=>“new”,

:controller=>“sessions”}

edit_session GET /session/edit(.:format) {:action=>“edit”,

:controller=>“sessions”}

         GET    /session(.:format)        {:action=>"show",

:controller=>“sessions”}

         PUT    /session(.:format)        {:action=>"update",

:controller=>“sessions”}

         DELETE /session(.:format)        {:action=>"destroy",

:controller=>“sessions”}

   login        /login(.:format)          {:action=>"new",

:controller=>“sessions”}

  logout        /logout(.:format)         {:action=>"destroy",

:controller=>“sessions”}

    root        /(.:format)               {:action=>"index",

:controller=>“words”}

But when i’m going to something like http://localhost:3000/words/22/test

i’m get error

Routing Error

No route matches “/words/22/test”

Why? what am I doing wrong?

Your route specifies PUT… but when you go to “/words/22/test” in the browser, that’s a GET request. So no, it’s not going to match. You could either change the route to respond to a GET request, or add a button or link that visits it via a PUT request.

Phil Crissman wrote in post #983406:

Phil

Phil Crissman wrote in post #983406:

test_word PUT /words/:id/test(.:format) {:action=>“test”,

:controller=>“words”}

        GET    /session(.:format)        {:action=>"show",

:controller=>“words”}

But when i’m going to something like http://localhost:3000/words/22/test

i’m get error

Routing Error

No route matches “/words/22/test”

Why? what am I doing wrong?

Your route specifies PUT… but when you go to “/words/22/test” in the

browser, that’s a GET request. So no, it’s not going to match. You could

either change the route to respond to a GET request, or add a button or

link

that visits it via a PUT request.

But when i create link like as

<%= link_to 'Test', :controller=>"words", :action=>"test" %>

get the same error

No route matches {:controller=>“words”, :action=>“test”}

Because that is still a GET request; you can see this in the logs as well. Also, you never provided a word :id

To make it a PUT request, you’d need to do <%=link_to ‘test’, test_word_path(@word), :method => :put %>

Why do you want it to be a PUT request? If you just want to link to it, 99.99% of the time, it should probably be a GET request.

Aegorov Egorov wrote in post #983420:

  <td><%= link_to 'Test', :controller=>"words", :action=>"test" %> get the same error No route matches {:controller=>"words", :action=>"test"}

1.i'm find the error. i forgot :id => word.id