Why does request.method return a string (instead of a character)?

I thought request.method should return a character like :get :put , etc.? But instead, in the controller action, I get GET as a string!

Am I doing something wrong?

In routes.rb :

 resources :posts member do get 'some_action' end end 

In the .erb view:

 <%= link_to "Some Action",some_action_post_path %> 

In PostsController :

 def some_action p request.method # => "GET" p request.method.class.name # => "String" if request.method == :get #does not get called end end 

Ps. I am using Rails 3.0.3 on Ruby 1.8.7 p330

+7
source share
3 answers

It works as designed - it is supposed to return a string :) So, use a string. Different topic: you can convert between strings and characters with to_s and to_sym respectively.

+10
source

For those who come up with this question when converting from Rails 2.x, it's worth noting that the call to request.method is used to return characters.

+9
source

All Articles