Alex Rivera | Logout

Why is `request.method` returning a string (instead of a symbol)?

Asked 2011-03-02T17:55:09.147
9

I thought request.method is supposed to return a symbol like :get, :put etc. ? But instead in the controller action, I am getting GET as a String!

Am I doing something wrong?

In routes.rb:

resources :posts
  member do
    get 'some_action'
  end
end

In a view .erb:

<%= 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'm using Rails 3.0.3 on Ruby 1.8.7 p330

Edit
Report

1 Answer

10

For anyone coming at this question while converting from Rails 2.x, it's worth noting that the request.method call used to return symbols.

answered 2011-05-09T05:55:37.863

Your Answer