Weird rjs partial rendering

See the output of the application at
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 %> <%[email protected]_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 %> <%[email protected]_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

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

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?

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

Fred

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?

: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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs