Another dumb RoR restriction

Some time ago I ran on session issue with Rails. During last days I spent a little time with RoR, but I have tried some new ideas and found another issue similar to sessions one.

Do not use send action in Your controller! Why?

Let assume we have some dumb controller (no views for it created) like:

class DumbController < ApplictionController
 def send
 end
end

I would expect that after pointing browser to http://localhost:3000/dumb/send I should get something like Template is missing. I got HTML 500 instead. In log/development.log we search for clue:

wrong number of arguments (1 for 0)
../config/../vendor/rails/actionpack/lib/action_controller/base.rb:427:in `send'

Well send is normal method defined in Actionpack, so when we define own method (action) named send it overrides Rails internal one and when ActionController::Base tries to call send (in line 427 of base.rb - Edge Rails) it calls with arguments:

      427         send(method, *arguments)

And Wrong number of arguments happen.

Solution? Don't use send action :))) Well since it looks like there is much more gotchas in Rails like this one, maybe it is time to think about some general solution? I'm not so advanced both in Rails and Ruby to propose solution. Maybe to call all Rails internal functions with underscore prefix? send would become _send and this said convention would prevent from running on such issues in future. I have to say that for some not knowing of this kind issues it can be sometimes misleading why it happens (I was clues when I ran on session issue, now I know that such things happen, and controller/method naming may have impact).

Other solution I can think of is some namespace using, but I'm not sure how exactly it can be achieved.

Join the Conversation

2 Comments

  1. once i’ve been bitten by this, as forgot that “send” is Ruby core method (not Rails internal)
    see
    ri Object#send
    :)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.