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
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
On Wed, Feb 23, 2011 at 12:09 PM, Aegorov E. [email protected]wrote:
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.
On Wed, Feb 23, 2011 at 12:09 PM, Aegorov E. [email protected]wrote:
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"}