# Weird rjs partial rendering

**URL:** <https://www.ruby-forum.com/t/weird-rjs-partial-rendering/74202>\
**Category:** Rails\
**Created:** [November 1, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/weird-rjs-partial-rendering/74202 "2006-11-01T17:21:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@sweb](https://www.ruby-forum.com/u/sweb)\
**Post date:** [November 1, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/weird-rjs-partial-rendering/74202/1 "2006-11-01T17:21:05Z")

</div>

See the output of the application at  
[http://www.samwoodard.com/mirador.pdf](http://www.samwoodard.com/mirador.pdf). I have partial month, which  
should actually be called “months”, but this is semantic:

| 

## \<%=Date::MONTHNAMES[@current\_two\_months[0][0].date.month] %\>
\<%for i in 0..6 %\> \<%end%\> \<% days\_in\_first\_week = 0 for i in 0..6 %\> \<%day=@current\_two\_months[0][days\_in\_first\_week]%\> \<% days\_in\_first\_week += 1 if @current\_two\_months[0][days\_in\_first\_week].date.wday == i end%\> \<%for day in @current\_two\_months[0][days\_in\_first\_week, @current\_two\_months[0].length - days\_in\_first\_week]%\> \<%if day.date.wday == 0%\>\<%end%\> \<%end%\> \<%end%\>

| \<%= Date::DAYNAMES[i][0,1] %\> |
| \<%=if day.date.wday == i && ( !session[:prebooking] || !session[:prebooking].end\_date) link\_to\_remote day.date.mday, :url =\> {:action =\> 'start\_date', :id =\> day}, :update =\> "months" elsif day.date.wday == i link\_to day.date.mday, {:action =\> 'check\_rate', :id =\> day} else end%\> |
| \<%=if !session[:prebooking] || !session[:prebooking].end\_date link\_to\_remote day.date.mday, :url =\> {:action =\> 'start\_date', :id =\> day}, :update =\> "months" else link\_to day.date.mday, {:action =\> 'check\_rate', :id =\> day} end%\> \<%if day.date.wday == 6%\> |

 | 

## \<%=Date::MONTHNAMES[@current\_two\_months[1][0].date.month] %\>
\<%for i in 0..6 %\> \<%end%\> \<% days\_in\_first\_week = 0 for i in 0..6 %\> \<%day=@current\_two\_months[1][days\_in\_first\_week]%\> \<% days\_in\_first\_week += 1 if @current\_two\_months[1][days\_in\_first\_week].date.wday == i end%\> \<%for day in @current\_two\_months[1][days\_in\_first\_week, @current\_two\_months[1].length - days\_in\_first\_week]%\> \<%if day.date.wday == 0%\>\<%end%\> \<%if day.date.wday == 6%\>\<%end%\> \<%end%\>

| \<%= Date::DAYNAMES[i][0,1] %\> |
| \<%= link\_to\_remote @current\_two\_months[1][days\_in\_first\_week].date.mday, :url =\> {:action =\> 'end\_date', :id =\> day} if @current\_two\_months[1][days\_in\_first\_week].date.wday == i %\> |
| \<%= link\_to\_remote day.date.mday, :url =\> {:action =\> 'end\_date', :id =\> day}%\> |

 |

which is rendered using an AJAX call to the action start\_date or  
end\_date. The rjs templates for start\_date and end\_date are the same:

#start\_date.rjs or end\_date.rjs  
page.replace\_html(“months” , :partial =\> “month” , :object =\>  
@current\_two\_months)

Why is this rendering doing what it is doing in the attached output?  
I’ve tried debugging the javascript, but I cannot find out what this “e”  
is that javascript is trying to output using e.toString() (see output).

The partial works fine before the javascript render.

What is going on here?

Thank you, Sam

---

<div class="post-metadata">

**Author:** ![sweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@sweb](https://www.ruby-forum.com/u/sweb)\
**Post date:** [November 1, 2006, 5:39pm UTC](https://www.ruby-forum.com/t/weird-rjs-partial-rendering/74202/2 "2006-11-01T17:39:54Z")

</div>

It looks like you’ve set :update on whatever variant of link\_to\_remote  
you’re using - this expects the ajax call to return a chunk of html,  
whereas you’re using an rjs, which returns a chunk of javascript to be  
evaluated.  
Since it’s expecting html, the ajax thingy just includes the rjs output  
verbatim in the page.

The e in question is the exception thrown should execution of the  
javascript fail.

Fred

---

<div class="post-metadata">

**Author:** ![sweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@sweb](https://www.ruby-forum.com/u/sweb)\
**Post date:** [November 1, 2006, 5:45pm UTC](https://www.ruby-forum.com/t/weird-rjs-partial-rendering/74202/3 "2006-11-01T17:45:16Z")

</div>

Frederick C. wrote:

> It looks like you’ve set :update on whatever variant of link\_to\_remote  
> you’re using - this expects the ajax call to return a chunk of html,  
> whereas you’re using an rjs, which returns a chunk of javascript to be  
> evaluated.  
> Since it’s expecting html, the ajax thingy just includes the rjs output  
> verbatim in the page.
> 
> The e in question is the exception thrown should execution of the  
> javascript fail.
> 
> Fred

So what do I do to fix it?

---

<div class="post-metadata">

**Author:** ![sweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@sweb](https://www.ruby-forum.com/u/sweb)\
**Post date:** [November 1, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/weird-rjs-partial-rendering/74202/4 "2006-11-01T17:47:38Z")

</div>

Either don’t use a :update in your link to remote or just render the  
partial instead of rendering the rjs.

Fred

---

<div class="post-metadata">

**Author:** ![sweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@sweb](https://www.ruby-forum.com/u/sweb)\
**Post date:** [November 1, 2006, 6:04pm UTC](https://www.ruby-forum.com/t/weird-rjs-partial-rendering/74202/5 "2006-11-01T18:04:21Z")

</div>

Frederick C. wrote:

> Either don’t use a :update in your link to remote or just render the  
> partial instead of rendering the rjs.
> 
> Fred

Is there a way to tell :update to render a partial in place of the DOM  
element stored there instead of a template named after the action called  
by the link\_to\_remote?

---

<div class="post-metadata">

**Author:** ![sweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@sweb](https://www.ruby-forum.com/u/sweb)\
**Post date:** [November 1, 2006, 6:08pm UTC](https://www.ruby-forum.com/t/weird-rjs-partial-rendering/74202/6 "2006-11-01T18:08:25Z")

</div>

:update doesn’t do that - it just generates the right js so that the  
correct DOM element is replaced with the result of the action.  
However, on your action you can call render with whatever parameters you  
feel like (for example render :partial =\> ‘month’, :object =\> foo)

Fred
