How to get a query string from a URL in Rails

前端 未结 4 1528
故里飘歌
故里飘歌 2020-11-28 23:15

Is there is a way to get the query string in a passed URL string in Rails?

I want to pass a URL string:

http://www.foo.com?id=4&empid=6
         


        
4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 23:59

    In a Ruby on Rails controller method the URL parameters are available in a hash called params, where the keys are the parameter names, but as Ruby "symbols" (ie. prefixed by a colon). So in your example, params[:id] would equal 4 and params[:empid] would equal 6.

    I would recommend reading a good Rails tutorial which should cover basics like this. Here's one example - google will turn up plenty more:

提交回复
热议问题