one template - multiple controllers?

How can I have just one layout for all controllers?


Controllers: project_controller todo_controller

views/layouts projects.rhtml todos.rhtml

How can I have just one layout for all controllers?

Say you want app/views/layouts/global.rhtml to be your template for everything... put the following into app/controllers/application.rb:

layout 'global'

Or, if you just want it for some controllers put that layout line in those controllers.

Or just make a views/layouts/application.rhtml (which will be the default if one named for the controller is not present).

Building on what Philip said, you can override the layout for an entire controller or just for a single action with:      render :layout => 'global'


Rob Biedenharn

Rails will use layouts/application.rhtml as a global layout... no need to configure....


Philip Hallstrom wrote:


I've done a bit of googling but I can't seem to find something in rails that converts metres to feet the way I need it.

Eg, I have a wall height of 1.70 metres, which i convert to 5.5777 feet using:

      def wall_height_to_ft         begin           (wall_height.to_f * 3.281).to_s   rescue     "0"   end

So the result I get is really still in metres times by 3.281. The result I need is 5 foot 7 inches or 5'7. Is there a easy way to do this in rails without calculating it myself?

Thanks in advance, Chris.

I misread the bottom part of your post. I don't think units will even do that conversion.

the problem is that when you take measurements in feet/inches, inches are typically measured down to the 16th or 32nd of an inch. don't know if you need that kind of precision or you just want the nearest inch.

so say you do the following

irb(main):032:0> wall_in_inches = 1.7.meters.to_inches => 66.92913379

so you could extract feet/inches by doing

irb(main):057:0> feet = (wall_in_inches/12).floor => 5 irb(main):055:0> inches = wall_in_inches.remainder(12).round => 7

technically, you don't even need units unless you need to do other unit conversions.

If you're going to do that, just use Numeric#divmod to get both values at once.

irb(main):004:0> puts(%{%d'%2.0f"} % 66.92913379.divmod(12)) 5' 7"


Rob Biedenharn

excellent thanks for your help guys.