Forum: Ruby on Rails newbie question about rendering partials and rhtml

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.
7da4a7b5be7f1e115861a253afb80641?d=identicon&s=25 gmoniey (Guest)
on 2007-05-04 19:12
(Received via mailing list)
Hi,

im not sure if i am on the right path here, so i figured i would ask.

Basically, all of my pages have the same header and footer, and i was
wondering if there was some way i could reference this from the rhtml
file?

from what i have read on partial and template rendering, this is done in
the
controller, but in my case, the header and footer are static, so there
is no
logic. Basically, I am just trying to minimize the number of places i
need
to edit in case i make a change to my header or footer (i.e. if i add a
link, i would really like to just update 1 file, rather than do it in
all of
my views).

Is this possible? thanks!
--
View this message in context:
http://www.nabble.com/newbie-question-about-render...
Sent from the RubyOnRails Users mailing list archive at Nabble.com.
8125afaa6ade422d5d733d7a05222935?d=identicon&s=25 Dave Goodchild (Guest)
on 2007-05-04 19:19
(Received via mailing list)
Have a look at layouts, that is precisely what they are for. For
example, if
you create an html skeleton, call it application.rhtml and place it in
the
layouts folder (in views/), the app will call it by default. In the area
where you want the controller-generated output to go, simply place this
call:

<% yield %>

and the magic will take place.

On 5/4/07, gmoniey <gmoniey@gmail.com> wrote:
>
> Is this possible? thanks!
> --
> View this message in context:
> 
http://www.nabble.com/newbie-question-about-render...
> Sent from the RubyOnRails Users mailing list archive at Nabble.com.
>
>
> >
>


--
http://www.web-buddha.co.uk
7da4a7b5be7f1e115861a253afb80641?d=identicon&s=25 gmoniey (Guest)
on 2007-05-05 01:35
(Received via mailing list)
Hi Dave,

I read up on layouts, (
http://www.onlamp.com/pub/a/onlamp/2005/03/03/rail...
http://www.onlamp.com/pub/a/onlamp/2005/03/03/rail... )

and it made me wonder why you cant specify a specific layout inside an
action? i tried placing the: layout "standard-layout" inside one of my
action def's, but i ended up with an error.

it this not possible?



Dave Goodchild wrote:
> and the magic will take place.
>> wondering if there was some way i could reference this from the rhtml
>> of
>>
>
>
> --
> http://www.web-buddha.co.uk
>
> >
>
>

--
View this message in context:
http://www.nabble.com/newbie-question-about-render...
Sent from the RubyOnRails Users mailing list archive at Nabble.com.
8310c5a7c769345114597bcdef111488?d=identicon&s=25 Ben Munat (Guest)
on 2007-05-05 09:51
(Received via mailing list)
The "layout 'standard-layout'" call is a class method call that sets the
layout for the whole controller.

To specify a specific layout for an action, pass it to render:

def fooaction
   # do something
   render :layout => 'super-special-layout'
end

b
7da4a7b5be7f1e115861a253afb80641?d=identicon&s=25 gmoniey@gmail.com (Guest)
on 2007-05-05 20:05
(Received via mailing list)
thanks for clearing that up...i have another question...this may be
more of a design question....our existing website has 2 templates, and
we determine which one to show based on screen size, which is
determined through javascript...i.e.

<script type="text/javascript">
<!-- Begin
        if(screen.width > xxx)
        {
                 window.location = "template1";

        }
        else {
                window.location='template2";
        }
// End -->
</script>

now i am trying to determine how to do this....basically all of my
actions behave the same, except they have a different layout...

but i am a bit confused...it doesnt seem like i can do this on the
server side...i.e. in the controller....or in the .rhtml file...so
should i redirect with a id specifying which template? (i.e. set the
window.location to specify the id in the url, and then base the
template on that?

im not sure if i have been very clear...so if this is confusing....let
me know...and i'll try and clear it up...
8125afaa6ade422d5d733d7a05222935?d=identicon&s=25 Dave Goodchild (Guest)
on 2007-05-05 22:09
(Received via mailing list)
I guess it depends how much of the difference between the two templates
is
presentational is handled by css. If so, the javascript can still do
it's
thing. The rhtml layouts should only contain structural information (ie
html/xhtml). Clarify a little more?

On 5/5/07, gmoniey@gmail.com <gmoniey@gmail.com> wrote:
>         {
> actions behave the same, except they have a different layout...
>
> >
> > > and it made me wonder why you cant specify a specific layout inside an
> in the
> > >> On 5/4/07,gmoniey<gmon...@gmail.com> wrote:
> > >>> file?
> > >>> to edit in case i make a change to my header or footer (i.e. if i
> http://www.nabble.com/newbie-question-about-render......
> > >>> Sent from the RubyOnRails Users mailing list archive at Nabble.com.
> >
> > >> --
> > >>http://www.web-buddha.co.uk
>
>
> >
>


--
http://www.web-buddha.co.uk
7da4a7b5be7f1e115861a253afb80641?d=identicon&s=25 gmoniey@gmail.com (Guest)
on 2007-05-06 00:40
(Received via mailing list)
the two layouts are actually very different...different images,
different static text, different tables, div's etc...

i have been thinkin about this more and more..and it seems like the
best way to do it would be something like this:


<script type="text/javascript">
 <!-- Begin
         if(screen.width > xxx)
         {
                  window.location = "http://www.mysite.com/template2";

        }
        else {
                 window.location='http://www.mysite.com/template1";
         }
  // End -->
</script>


and have the action handle which template will be shown from there on
out (since this really only need to be figured out the first time the
page loads), however...im worried about the case where the user wanted
to go back to the homepage...i.e. http://www.mysite.com, i would need
a way to ensure that the javascript is run again...
E3513c4edd6810bb4b9914b58da2a2c3?d=identicon&s=25 Jamal Soueidan (jamal)
on 2007-05-06 01:49
gmoniey wrote:
> Hi,
>
> im not sure if i am on the right path here, so i figured i would ask.
>
> Basically, all of my pages have the same header and footer, and i was
> wondering if there was some way i could reference this from the rhtml
> file?
>

In the view you can do this

<%= render "blog/header" %>

blah lbah

<%= render "blog/footer" %>

PS: I would rather create one layout which include header and footer :)
This topic is locked and can not be replied to.