# Making a public controller in an extension

**URL:** <https://www.ruby-forum.com/t/making-a-public-controller-in-an-extension/139139>\
**Category:** Radiant CMS\
**Created:** [May 31, 2008, 10:07am UTC](https://www.ruby-forum.com/t/making-a-public-controller-in-an-extension/139139 "2008-05-31T10:07:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![squeegy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@squeegy](https://www.ruby-forum.com/u/squeegy)\
**Post date:** [May 31, 2008, 10:07am UTC](https://www.ruby-forum.com/t/making-a-public-controller-in-an-extension/139139/1 "2008-05-31T10:07:17Z")

</div>

I have a simple extension with a controller that I want to be publicly  
accessible. The problem is that when I access it, it uses the admin  
layout. How do I get the views from my controller to render in the my  
site layout as defined by the “Layouts” tab?

It seems to work just fine otherwise, but obviously, the admin layout is  
not something I want to show to the public.

---

<div class="post-metadata">

**Author:** ![squeegy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@squeegy](https://www.ruby-forum.com/u/squeegy)\
**Post date:** [May 31, 2008, 11:13am UTC](https://www.ruby-forum.com/t/making-a-public-controller-in-an-extension/139139/2 "2008-05-31T11:13:11Z")

</div>

Alex W. wrote:

> I have a simple extension with a controller that I want to be publicly  
> accessible. The problem is that when I access it, it uses the admin  
> layout. How do I get the views from my controller to render in the my  
> site layout as defined by the “Layouts” tab?
> 
> It seems to work just fine otherwise, but obviously, the admin layout is  
> not something I want to show to the public.

After some hacking and reverse engineering the Radiant rendering code, I  
managed to come up with this rediculous hack:

[http://pastie.caboo.se/206357](http://pastie.caboo.se/206357)

That is probably just about the ugliest thing ever. I tried doing a:

@page.parts.new(:name =\> ‘body’, :content =\> render\_to\_string)

But that just left me with blank content. So gsubbing the \<r:content /\>  
tag for the actual rendered template was the next best thing.

Maybe I am completely missing the radiant golden path here. Should I  
write some radius tags that will let me access this data in a page  
object instead? If so, how do I access the params[:id] in order to  
retrieve the right objects from the database? And how do I make a page  
render for a URL with a variable parameter?

Perhaps, I should create a page object via the admin with HTML, title,  
layout, etc. Then set it up with a specific slug I can easily retrieve.  
Then render that page with my own render\_to\_string as the body page part  
content? Still seems weird to manually mess with a page object here to  
achieve what seems to be a simple thing.

---

<div class="post-metadata">

**Author:** ![squeegy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@squeegy](https://www.ruby-forum.com/u/squeegy)\
**Post date:** [May 31, 2008, 11:35am UTC](https://www.ruby-forum.com/t/making-a-public-controller-in-an-extension/139139/3 "2008-05-31T11:35:36Z")

</div>

Have you considered the share\_layouts extension?

[http://dev.radiantcms.org/browser/trunk/extensions/share\_layouts/README](http://dev.radiantcms.org/browser/trunk/extensions/share_layouts/README)

It’s designed for this purpose.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![squeegy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@squeegy](https://www.ruby-forum.com/u/squeegy)\
**Post date:** [May 31, 2008, 11:50am UTC](https://www.ruby-forum.com/t/making-a-public-controller-in-an-extension/139139/4 "2008-05-31T11:50:35Z")

</div>

John W. Long wrote:

> Have you considered the share\_layouts extension?
> 
> [http://dev.radiantcms.org/browser/trunk/extensions/share\_layouts/README](http://dev.radiantcms.org/browser/trunk/extensions/share_layouts/README)
> 
> It’s designed for this purpose.
> 
> –  
> John L.  
> [http://wiseheartdesign.com](http://wiseheartdesign.com)

Well that certainly makes things easier. Guess I need to do more  
research and less late night caffeine induced hack sessions.

Thanks, it works like a charm.
