# RJS and layouts

**URL:** <https://www.ruby-forum.com/t/rjs-and-layouts/52179>\
**Category:** Rails\
**Created:** [January 11, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/rjs-and-layouts/52179 "2006-01-11T19:15:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [January 11, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/rjs-and-layouts/52179/1 "2006-01-11T19:15:18Z")

</div>

Hi all,

I’ve been using RJS more and more for my app and I have sorta run into a  
possible issue. My app has different user roles that require different  
layouts. So far, this has worked fine, but now that I’m using rjs more  
and more I’m finding that the two don’t really work together since I  
have to rails not to use a layout upon controller method completion.

This isn’t stopping my development and I understand (I think) all the  
issues regarding this and have so far been able to deal with them.  
However, I can sorta see where this is all going and the more I rely on  
rjs, the less I rely on templates.

Has anyone else run into any issues re: this and if so, how have you  
solved them?

Thx,

jason

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [January 11, 2006, 7:24pm UTC](https://www.ruby-forum.com/t/rjs-and-layouts/52179/2 "2006-01-11T19:24:31Z")

</div>

On 1/11/06, Jason [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> However, I can sorta see where this is all going and the more I rely on  
> rjs, the less I rely on templates.
> 
> Has anyone else run into any issues re: this and if so, how have you  
> solved them?
> 
> Thx,
> 
> jason

Several possible solutions:

class RjsController \< ActionController::Base

# Turns off layouts globally, use this for rjs only actions

layout nil

# specify rjs actions

layout nil, :only =\> [:rjs\_edit, :rjs\_update]  
end

–  
rick  
[http://techno-weenie.net](http://techno-weenie.net)

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [January 11, 2006, 7:30pm UTC](https://www.ruby-forum.com/t/rjs-and-layouts/52179/3 "2006-01-11T19:30:36Z")

</div>

On Wed, Jan 11, 2006 at 07:15:18PM +0100, Jason wrote:

> I’ve been using RJS more and more for my app and I have sorta run into a  
> possible issue. My app has different user roles that require different  
> layouts. So far, this has worked fine, but now that I’m using rjs more  
> and more I’m finding that the two don’t really work together since I  
> have to rails not to use a layout upon controller method completion.

I’m not following entirely. Specifically around:

> now that I’m using rjs more  
> and more I’m finding that the two don’t really work together since I  
> have to rails not to use a layout upon controller method completion.

Should this read, “since I have to _tell_ rails not to use a layout upon  
controller method completion”? And if so what do you mean? When calling  
actions that render rjs? Layouts are automatically skipped when  
rendering  
rjs. Is that not what you mean? Do you mean having to have the rjs  
update  
elements which could be in either layout? Shared naming conventions?

marcel

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [January 11, 2006, 7:40pm UTC](https://www.ruby-forum.com/t/rjs-and-layouts/52179/4 "2006-01-11T19:40:08Z")

</div>

Marcel Molina Jr. wrote:

> On Wed, Jan 11, 2006 at 07:15:18PM +0100, Jason wrote:
> 
> > I’ve been using RJS more and more for my app and I have sorta run into a  
> > possible issue. My app has different user roles that require different  
> > layouts. So far, this has worked fine, but now that I’m using rjs more  
> > and more I’m finding that the two don’t really work together since I  
> > have to rails not to use a layout upon controller method completion.
> 
> I’m not following entirely. Specifically around:
> 
> > now that I’m using rjs more  
> > and more I’m finding that the two don’t really work together since I  
> > have to rails not to use a layout upon controller method completion.
> 
> Should this read, “since I have to _tell_ rails not to use a layout upon  
> controller method completion”? And if so what do you mean? When calling  
> actions that render rjs? Layouts are automatically skipped when  
> rendering  
> rjs. Is that not what you mean? Do you mean having to have the rjs  
> update  
> elements which could be in either layout? Shared naming conventions?
> 
> marcel

Yah, sorry, typo. Should be ‘I have to tell…’. I didn’t know that rjs  
bypassed layouts, but it makes sense.

As for rjs updating elements, yeah, and in my case I’ve chosen to have  
big blocks updated to avoid page refreshes. When I didn’t use rjs, the  
layouts took care of the obvious in regards to my user roles, which are  
linked to a particular layout. But now, I’m finding that I have to  
update more elements when I go from section to section as I’m no longer  
doing page refreshes.

So if, for instance, someone goes from reading some news to then  
clicking on a link to go to the admin section, my rjs files now how to  
do multiple element changes/updates. In my case it seems unavoidable  
which is fine, and I was just wanting to know if anyone else has chosen  
this path and if they had any examples or thoughts regarding the matter.

Thx

- jason

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [January 11, 2006, 9:32pm UTC](https://www.ruby-forum.com/t/rjs-and-layouts/52179/5 "2006-01-11T21:32:50Z")

</div>

Marcel Molina Jr. wrote:

> On Wed, Jan 11, 2006 at 07:40:08PM +0100, Jason wrote:
> 
> > > > now that I’m using rjs more
> > > 
> > > marcel
> > 
> > So if, for instance, someone goes from reading some news to then  
> > clicking on a link to go to the admin section, my rjs files now how to  
> > do multiple element changes/updates. In my case it seems unavoidable  
> > which is fine, and I was just wanting to know if anyone else has chosen  
> > this path and if they had any examples or thoughts regarding the matter.
> 
> Using Ajax (and in this case rjs) for this kind of site navigation can  
> have  
> some shortcomings from a usability stand point. Users don’t have access  
> to a  
> uri so they can’t link to or bookmark or otherwise get directly to a  
> part of  
> your site without clicking one or more times.
> 
> marcel

Right and for my usage, these things are ok as most of this is under a  
logged in umbrella and we’re ok with bookmarking not working at this  
level.

Hopefully there will be more examples of people using rjs so I can get a  
better feel of other ways it’s being used.

-j

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [January 11, 2006, 8:44pm UTC](https://www.ruby-forum.com/t/rjs-and-layouts/52179/6 "2006-01-11T20:44:08Z")

</div>

On Wed, Jan 11, 2006 at 07:40:08PM +0100, Jason wrote:

> > > now that I’m using rjs more
> > 
> > marcel
> 
> So if, for instance, someone goes from reading some news to then  
> clicking on a link to go to the admin section, my rjs files now how to  
> do multiple element changes/updates. In my case it seems unavoidable  
> which is fine, and I was just wanting to know if anyone else has chosen  
> this path and if they had any examples or thoughts regarding the matter.

Using Ajax (and in this case rjs) for this kind of site navigation can  
have  
some shortcomings from a usability stand point. Users don’t have access  
to a  
uri so they can’t link to or bookmark or otherwise get directly to a  
part of  
your site without clicking one or more times.

marcel
