views:

54

answers:

4

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 only accept post method, can I do so?

+3  A: 
class UsersController < ApplicationController 
  verify :method => :post, :only => :doSomethingAgain

  def doSomething
  end

  def doSomethingAgain
  end

end
Draco Ater
You need to use a symbol or a string when passing the action name in `:only`. @Draco I've edited your answer - hope that is OK.
mikej
Yes, you are right, thanks
Draco Ater
A: 

Here example

resources :products do
  resource :category

  member do
    post :short
  end

  collection do
    get :long
  end
end
+1  A: 

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] }
Bohdan Pohorilets
A: 

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
thenduks