For example:
class UsersController < ApplicationController
def doSomething
end
def doSomethingAgain
end
end
Can I restrict the user pass a get method only to doSomething, but doSomethingAgain is o开发者_开发问答nly accept post method, can I do so?
class UsersController < ApplicationController
verify :method => :post, :only => :doSomethingAgain
def doSomething
end
def doSomethingAgain
end
end
You may specify in routes.rb
map.resources :users, :collection=>{
:doSomething= > :get,
:doSomethingAgain => :post }
You may specify more then one method
map.resources :users, :collection=>{
:doSomething= > [:get, :post],
:doSomethingAgain => [:post, :put] }
Here example
resources :products do
resource :category
member do
post :short
end
collection do
get :long
end
end
I think you'll be best off with using verify
as Draco suggests. But you could also just hack it like this:
def doSomethingAgain
unless request.post?
redirect_to :action => 'doSomething' and return
end
# ...more code
end
精彩评论