Forum: Ruby on Rails one template - multiple controllers?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cab0742af6fb712360d9e31e53693051?d=identicon&s=25 seanstewart (Guest)
on 2007-03-07 20:25
(Received via mailing list)
How can I have just one layout for all controllers?

Ex:

Controllers:
project_controller
todo_controller

views/layouts
projects.rhtml
todos.rhtml
2f9a03aa0fcfe945229cb6126eda2cb2?d=identicon&s=25 Philip Hallstrom (Guest)
on 2007-03-07 20:34
(Received via mailing list)
> 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.
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2007-03-07 20:40
(Received via mailing list)
On Mar 7, 2007, at 2:43 PM, Philip Hallstrom 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 Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
8310c5a7c769345114597bcdef111488?d=identicon&s=25 Ben Munat (Guest)
on 2007-03-07 22:43
(Received via mailing list)
Rails will use layouts/application.rhtml as a global layout... no need
to configure....

b
4287232616a1dde31cd2dab154acad70?d=identicon&s=25 Pepe Sanchez (jsn1)
on 2007-04-02 13:49
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
7cd126348f5698add9f8287acb0425f2?d=identicon&s=25 Chris H (Guest)
on 2007-04-02 14:56
(Received via mailing list)
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.
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-04-02 16:14
(Received via mailing list)
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-04-02 16:36
(Received via mailing list)
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.
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2007-04-02 17:30
(Received via mailing list)
On Apr 2, 2007, at 10:35 AM, Chris Hall 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 Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
7cd126348f5698add9f8287acb0425f2?d=identicon&s=25 Chris H (Guest)
on 2007-04-03 01:55
(Received via mailing list)
excellent thanks for your help guys.
This topic is locked and can not be replied to.