Identify GET and POST parameters in Ruby on Rails

前端 未结 11 769
我在风中等你
我在风中等你 2020-12-08 14:16

What is the simplest way to identify and separate GET and POST parameters from a controller in Ruby on Rails, which will be equivalent to $_GET and $_POST variables in PHP?<

11条回答
  •  遥遥无期
    2020-12-08 15:01

    If you want to check the type of request in order to prevent doing anything when the wrong method is used, be aware that you can also specify it in your routes.rb file:

    map.connect '/posts/:post_id', :controller => 'posts', :action => 'update', :conditions => {:method => :post} 
    

    or

    map.resources :posts, :conditions => {:method => :post} 
    

    Your PostsController's update method will now only be called when you effectively had a post. Check out the doc for resources.

提交回复
热议问题