Hello!
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
Help!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 13 Mar 2008, at 09:26, sinm wrote:> > Hello! > > 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 > endIf I were you I''d remove that rescue nil statement as that will swallow any errors that might be telling you what is wrong. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ActionController::DoubleRenderError (Can only render or redirect once per action) raises. So, thats the problem - I cant "inject" RJS into template. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Anyone? On Mar 13, 12:26 pm, sinm <sinm.s...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello! > > 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 > > Help!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 13 Mar 2008, at 12:23, sinm wrote:> > Anyone?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. Fred.> > > On Mar 13, 12:26 pm, sinm <sinm.s...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Hello! >> >> 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 >> >> Help! > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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? On Mar 13, 3:37 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 13 Mar 2008, at 12:23, sinm wrote: > > > > > Anyone? > > 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. > > Fred. > > > > > On Mar 13, 12:26 pm, sinm <sinm.s...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Hello! > > >> 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 > > >> Help!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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
mercy
blog.odeley.com
On 13 Mrz., 13:23, sinm
<sinm.s...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Anyone?
>
> On Mar 13, 12:26 pm, sinm
<sinm.s...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
>
> > Hello!
>
> > 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
>
> > Help!- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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. On Mar 13, 3:46 pm, maerzbow <maerz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > mercy > blog.odeley.com > > On 13 Mrz., 13:23, sinm <sinm.s...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Anyone? > > > On Mar 13, 12:26 pm, sinm <sinm.s...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hello! > > > > 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 > > > > Help!- Zitierten Text ausblenden - > > > - Zitierten Text anzeigen ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
sinm wrote:> 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: after_filter :clear_notice_on_xhr def clear_notice_on_xhr new_text = "New flash notice created here" script = <<EOS <script type="text/javascript"> //<![CDATA[ $(''notice'').update(''#{new_text}'') //]]> </script> EOS response.body << script end 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". -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanx Mark for your try!
Really messy but it really works.
Finally i ended up with slightly different version.
after_filter :clear_notice_on_xhr
#TODO: bad smell
def clear_notice_on_xhr
return unless request.xhr?
response.body =
"$(''notice'').update('''');" +
response.body
rescue
nil #optional
end
On Mar 13, 7:06 pm, Mark Bush
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> sinm wrote:
> > 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:
>
> after_filter :clear_notice_on_xhr
>
> def clear_notice_on_xhr
> new_text = "New flash notice created here"
> script = <<EOS
> <script type="text/javascript">
> //<![CDATA[
> $(''notice'').update(''#{new_text}'')
> //]]>
> </script>
> EOS
> response.body << script
> end
>
> 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".
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---