Rails 3 – PHP Style Global Variables, $_SESSION, $_GET, $_POST in the models, and everywhere.

PHP Globals in Rails 3

So, as part of my slow descent into hell for even showing this stuff, I thought I would make a quick and dirty post about getting PHP like globals into your models in Rails. I wrote a longer article about globals in the model in rails which you can check out for some other options.

def some_before_filter
  $_SESSION = session
  $_GET = request.GET
  $_POST = request.POST
  $GLOBALS = {}
end

Yeah, that simple. When it comes to globals, the ruby and rails community is kind of like the child of a former Nazi sympathizer who got off the hook at Nuremburg. Yeah, they’re related, but they just don’t want to have anything to do with them, and if you remind them of the connection they get really angry.

About Jason

I am a 26 year old programmer living in the south of France. I currently work actively in the fields of Ruby/PHP/Javascript and server/website administration.
This entry was posted in Computer Science, PHP Tutorials, PHP/MySQL, Ruby on Rails, Ruby on Rails, Tips and Tricks, Topics, Tutorials. Bookmark the permalink.