Layouts in Rails...

B

Brock Weaver

------=_Part_4693_10897249.1123879708752
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I apologize if this the incorrect mailing list, as it is a Rails question,=
=20
not really a Ruby question. Anyway:

To apply a layout to a controller, you can say:

class UsersController < ApplicationController
layout "master"
end

...which you would need to do in every controller. So my first thought is t=
o=20
push this down into ApplicationController, mitigating the need to put=20
anything layout related in all the other controllers:

class ApplicationController < ActionController::Base
layout "master"
end

...which doesn't work. So my next thought is to declare an instance variabl=
e=20
in the ApplicationController:

class ApplicationController < ActionController::Base
@layout =3D "master"
end

and change all other controllers to look like this:

class UsersController < ApplicationController
layout @layout
end

...which doesn't work either. So I grudgingly try a global with the same=20
thought process:

class ApplicationController < ActionController::Base
$layout =3D "master"
end

class UsersController < ApplicationController
layout $layout
end

...which works. But I don't understand why, if UsersController derives from=
=20
ApplicationController, the other two methodologies fail. Can someone explai=
n=20
this to me?=20

Centralizing the layout moniker to one place will help significantly as I=
=20
move my app from test/dev/prod, so I can have alarmingly different layouts=
=20
for test/dev versus production.

--=20
Brock Weaver
http://www.circaware.com

------=_Part_4693_10897249.1123879708752--
 
S

Sean T Allen

--------------070705050508040600080602
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

putting layout in ApplicationController always works for me...

perhaps you have an odd typo or something somewhere?



--------------070705050508040600080602
Content-Type: text/x-vcard; charset=utf-8;
name="sean.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="sean.vcf"

begin:vcard
fn:Sean T. Allen
n:Allen;Sean T.
org:Ardis Marketing Group
adr;dom:;;;New York;NY
email;internet:[email protected]
title:Tech Guru
x-mozilla-html:FALSE
url:http://ardismg.com/
version:2.1
end:vcard


--------------070705050508040600080602--
 
B

Brock Weaver

------=_Part_4818_12528732.1123881450786
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Thanks for the lead, Sean. I'd used the generate scaffold to create the=20
usuals, and it created users.rhtml. When this file exists, it seems to=20
ignore the layout method in my ApplicationController, as I'm guessing the=
=20
users.rhtml is more specific / overrides that value.

Deleting the users.rhtml file resulted in the expected behavior. Thanks=20
again!

=20
putting layout in ApplicationController always works for me...
=20
perhaps you have an odd typo or something somewhere?
=20
=20
=20
=20
=20


--=20
Brock Weaver
http://www.circaware.com

------=_Part_4818_12528732.1123881450786--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top