# Render yield?!

**URL:** <https://www.ruby-forum.com/t/render-yield/161982>\
**Category:** Rails\
**Created:** [March 4, 2009, 2:43pm UTC](https://www.ruby-forum.com/t/render-yield/161982 "2009-03-04T14:43:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cojones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@cojones](https://www.ruby-forum.com/u/cojones)\
**Post date:** [March 4, 2009, 2:43pm UTC](https://www.ruby-forum.com/t/render-yield/161982/1 "2009-03-04T14:43:39Z")

</div>

Hello,

I’ve got a little problem with remote functions. I call it for example  
like this: \<%= link\_to\_remote ‘bla’, :url =\> ‘bla/whatever’, :method =\>  
:get %\>

that function would be:  
def whatever  
flash[:notice] = “You’re in whatever!”  
update\_content  
end

since I don’t want the page to be reloaded completely, I update each div  
box that needs to be updated:  
def update\_content  
render :update do |page|  
page.replace ‘loginBox’, :partial =\> ‘shared/login’  
page.replace ‘contentBox’, :partial =\> ‘shared/content’  
page.replace ‘navigation’, :partial =\> ‘shared/navigation’  
page.replace ‘menuBox’, :partial =\> ‘shared/menu’  
end  
end

My problem nos is that the partial views/shared/\_content.html.erb has a  
yield which doesn’t show me the content of views/bla/whatever.html.erb  
anymore and only shows it when I access it directly (not using remote  
functions).

Does anyone know how I possibly could still show the content of the  
template of each action where yield is?

My other approach was:  
\<%= link\_to\_remote ‘bla’, :url =\> ‘bla/whatever’, :update =\>  
‘contentBox’, :method =\> :get %\>

def whatever  
flash[:notice] = “You’re in whatever!”  
respond\_to do |format|  
format.html  
format.xml { head :ok }  
end  
end

That would show the template as I want it but doesn’t update login,  
navigation and menuBox.

Any ideas? I’m kind out of ideas… ☹

---

<div class="post-metadata">

**Author:** ![cojones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@cojones](https://www.ruby-forum.com/u/cojones)\
**Post date:** [March 4, 2009, 5:14pm UTC](https://www.ruby-forum.com/t/render-yield/161982/2 "2009-03-04T17:14:45Z")

</div>

I just figured out you can use

yield(page)

def update\_content  
render :update do |page|  
page.replace ‘loginBox’, :partial =\> ‘shared/login’  
page.replace ‘contentBox’, :partial =\> ‘shared/content’  
page.replace ‘navigation’, :partial =\> ‘shared/navigation’  
page.replace ‘menuBox’, :partial =\> ‘shared/menu’  
-----\> yield(page) \<-----  
end  
end

but yield wants some block, if I pass a String in the block nothing  
really happens…

---

<div class="post-metadata">

**Author:** ![cojones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@cojones](https://www.ruby-forum.com/u/cojones)\
**Post date:** [March 4, 2009, 6:58pm UTC](https://www.ruby-forum.com/t/render-yield/161982/3 "2009-03-04T18:58:29Z")

</div>

Even though it became some monolog already…

I found a not so good solution to my problem:  
def update\_content  
render :update do |page|  
page.replace ‘loginBox’, :partial =\> ‘shared/login’  
page.replace ‘navigation’, :partial =\> ‘shared/navigation’  
page.replace ‘menuBox’, :partial =\> ‘shared/menu’  
page.replace ‘contentBody’, :file =\> ‘bla/whatever’  
end  
end

Is :file a proper solution? If so, is there any variable that tells me  
where the call is coming from (in my case it’s called whatever) so I  
don’t have to give the :file path as a parameter whenever I call it?

---

<div class="post-metadata">

**Author:** ![cojones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@cojones](https://www.ruby-forum.com/u/cojones)\
**Post date:** [March 4, 2009, 6:27pm UTC](https://www.ruby-forum.com/t/render-yield/161982/4 "2009-03-04T18:27:46Z")

</div>

I’m desperate… is there no way to somehow render the default template  
AND do some render :update or include the default template in render  
:update?

---

<div class="post-metadata">

**Author:** ![cojones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@cojones](https://www.ruby-forum.com/u/cojones)\
**Post date:** [March 4, 2009, 9:10pm UTC](https://www.ruby-forum.com/t/render-yield/161982/5 "2009-03-04T21:10:22Z")

</div>

On Wed, Mar 4, 2009 at 8:46 PM, Peter V.

> request.uri etc (that variable is available in the views)
> 
> More details for request.uri and (lots of) friends:
> 
> [http://api.rubyonrails.org/classes/ActionController/Request.html#M000694](http://api.rubyonrails.org/classes/ActionController/Request.html#M000694)

Sorry, I was mistaken, request.uri does not exist

What does exist is

- request.request\_uri
- request.url

The results of a small test:

request.request\_uri = /home  
request.url = [http://localhost:3000/home](http://localhost:3000/home)

These 2 attributes are available both in the controller and in the  
views.

HTH,

Peter

---

<div class="post-metadata">

**Author:** ![cojones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@cojones](https://www.ruby-forum.com/u/cojones)\
**Post date:** [March 4, 2009, 8:50pm UTC](https://www.ruby-forum.com/t/render-yield/161982/6 "2009-03-04T20:50:15Z")

</div>

On Wed, Mar 4, 2009 at 6:58 PM, Heinz S.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If so, is there any variable that tells me  
> where the call is coming from (in my case it’s called whatever) so I  
> don’t have to give the :file path as a parameter whenever I call it?

I am not sure I understand your question.

Would you mean something like

request.uri etc (that variable is available in the views)

or simply

controller.action\_name (available in the views)

More details for request.uri and (lots of) friends:

[http://api.rubyonrails.org/classes/ActionController/Request.html#M000694](http://api.rubyonrails.org/classes/ActionController/Request.html#M000694)

for the controller.action\_name:

[ActionController and what the heck is attr\_internal? | Chronicling My Ruby on Rails Journey](http://rubyonrailswin.wordpress.com/2007/03/07/actioncontroller-and-what-the-heck-is-attr_internal/)

Was that your question ?

HTH,

Peter

---

<div class="post-metadata">

**Author:** ![cojones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@cojones](https://www.ruby-forum.com/u/cojones)\
**Post date:** [March 4, 2009, 9:16pm UTC](https://www.ruby-forum.com/t/render-yield/161982/7 "2009-03-04T21:16:27Z")

</div>

self.controller\_name and self.action\_name was what I was looking for,  
thanks.

Anyone knows an alternative for:  
page.replace ‘contentBody’, :file =\>  
self.controller\_name+’/’+self.action\_name?

Looks pretty dirty…
