Re: Difference between local and live server...

javier ramirez
Thu, 30 Aug 2007 17:01:21 -0000

Hi,

> I''m setting my layout in a before_filter.
>
> before_filter :find_current_site
>
> layout $layout
>
> def find_current_site
>
> It''s working on my local mongrel server, but on my live server
(also
> mongrel) I always end up with no layout, no matter how many times I
> refresh.
>
> Does anyone know what is going on here?
>
yep.. when you are in development mode, the classes (most of them
anyhow) get reloaded at each request. This means the code is
reinterpreted every time and that''s why: a) you don''t need to
restart so
it''s cool to try things quickly, and: b) it''s much slower than
running
in production mode.

When in production, the classes get interpreted when loaded, and they
are not reinterpreted every time. That''s why you need to restart the
server when you change the code. This means the class variables will
keep their values between calls unless you modify them explicitely. So
what''s going on is first time you reference your controller, variable
$layout doesn''t have any value, so you get a nil there. Then no matter
what you do, the nil is there between calls.

There are different approaches to this, the most similar to your
solution being just to use a proc instead of a value for the layout. You
can say layout :find_current_site and then that method must return a
String with the layout name. That should do the trick.

Also, using global variables is generally speaking a bad idea if you
want to make solid modular code, so I''d try to avoid them when
possible.

regards,

javier ramirez