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.
seanstewart (Guest)
on 2007-03-07 21: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
Philip H. (Guest)
on 2007-03-07 21: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.
Rob B. (Guest)
on 2007-03-07 21:40
(Received via mailing list)
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
Ben M. (Guest)
on 2007-03-07 23:43
(Received via mailing list)
Rails will use layouts/application.rhtml as a global layout... no need
to configure....

b
Pepe S. (Guest)
on 2007-04-02 15: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
Chris H (Guest)
on 2007-04-02 16: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.
Chris H. (Guest)
on 2007-04-02 18:14
(Received via mailing list)
Chris H. (Guest)
on 2007-04-02 18: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.
Rob B. (Guest)
on 2007-04-02 19:30
(Received via mailing list)
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
Chris H (Guest)
on 2007-04-03 03:55
(Received via mailing list)
excellent thanks for your help guys.
This topic is locked and can not be replied to.