Get a problem out here. I need to update flash notice with every one
remote request. Flash.now[:notice] does that trick but not for
remoting methods. So I’ve applied some after_filter (say
clear_notice_on_xhr) but its render method not evaluating or i can’t
see the result:
def clear_notice_on_xhr
return unless request.xhr?
render :update do |page|
page.replace_html(“notice” , :partial => “layouts/notice”)
end
rescue
nil
end
You;ve already found the problem: you’ve already rendered, so you
can’t render again. If people could see the whole story rather than
just one bit, someone might be able to suggest an alternative.
I think it does not work to implement it as ‘after_filter’ as long the
action executed before that filter calls ‘render’, too.
so for example:
def index
…
calls (implecitely) render index.erb.html # or in your case
another rjs
end
def clear_notice_on_xhr
return unless request.xhr?
# CALLS RENDER AGAIN ON THE SAME HTTP REQUEST
# that doesnt work 'cause IMHO rails does not know how to merge
these 2 render outputs
render :update do |page|
page.replace_html(“notice” , :partial => “layouts/notice”)
end
rescue
nil
end
I found the problem but i dont know how to solve it.
Story:
I want to evaluate the same page.replace_html method in every rjs
template.
Question:
How to do that?
Ok. I know from the beginning that DoubleRenderError, but how to
include that same page.replace_html method in every rjs
template? Rails seemed to be dynamic and powerful but in fact i cant
implement that very simple scenario… silly.
Rather than use a partial, create the text in your after_filter method
and add a call to the end of the response body to action it as
javascript. This is a little messy, but you could hide it away. There
may well be an easier way, but this seems to work for me:
This assumes you are including the Prototype javascript library in your
pages (will need re-writing otherwise) and the tag where you display
your flash has an id of “notice”.
Ok. I know from the beginning that DoubleRenderError, but how to
include that same page.replace_html method in every rjs
template? Rails seemed to be dynamic and powerful but in fact i cant
implement that very simple scenario… silly.