One template - multiple controllers?


#1

How can I have just one layout for all controllers?

Ex:

Controllers:
project_controller
todo_controller

views/layouts
projects.rhtml
todos.rhtml


#2

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.


#3

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

b


#4

On Mar 7, 2007, at 2:43 PM, Philip H. wrote:

Ex:

Controllers:
project_controller
todo_controller

views/layouts
projects.rhtml
todos.rhtml

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

Rob B. http://agileconsultingllc.com
removed_email_address@domain.invalid


#5

Howdy,

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
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.


#6

http://rubyforge.org/projects/units/


#7

See here http://railscasts.com/episodes/7

seanstewart wrote:

How can I have just one layout for all controllers?

Ex:

Controllers:
project_controller
todo_controller

views/layouts
projects.rhtml
todos.rhtml


#8

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.


#9

excellent thanks for your help guys.


#10

On Apr 2, 2007, at 10:35 AM, Chris H. wrote:

that converts metres to feet the way I need it.
end
do that conversion.

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

Rob B. http://agileconsultingllc.com
removed_email_address@domain.invalid