Hi, I have solved this issue by myself, but I think it''s a dirty way to go. Please if someone knows a better way to do it, please let me know. This is how I call JS from the controller controller.rb: def someAction render :text => "JSfoo()", :content_type => "text/javascript" end and this is how I call it from RJS RJSfoo.rjs: page << ''JSfoo()'' Why doesn''t the RJS method work in the controller (I tried it), and is there a better way to call JS from the controller? Thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
MaM o_0 wrote:> Hi, > I have solved this issue by myself, but I think it''s a dirty way to go. > Please if someone knows a better way to do it, please let me know. > > This is how I call JS from the controller > controller.rb: > def someAction > render :text => "JSfoo()", > :content_type => "text/javascript" > end > > and this is how I call it from RJS > RJSfoo.rjs: > page << ''JSfoo()'' > > Why doesn''t the RJS method work in the controller (I tried it), and is > there a better way to call JS from the controller? > Thanks! > > -- > Posted via http://www.ruby-forum.com/.How about this... in your controllerj def some_action render :update do |page| page.call "JSfoo" end end _Kevin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
_Kevin wrote:> How about this... in your controllerj > > def some_action > render :update do |page| > page.call "JSfoo" > end > end > > _KevinThank you _Kevin! Works like a charm ;). If you would tell me how to pass an argument to the JS function, you''d be a life-saver! Thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
I figured that one on my own, here''s my way of doing it: def some_action @some_arg = 3 render :update do |page| page.call ("JSfoo", @some_arg) end end If you know a better way, please let me know, or how could this argument be an (javascript) array. Maybe that''s too much;)? cheers! -- 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 -~----------~----~----~----~------~----~------~--~---
I''m again answering my own question, I hope it''ll help someone else. Here is how I pass an array to javascript function. def some_action @some_arg = [1,2,3] render :update do |page| page.call ("JSfoo", @some_arg) end end Ruby on Rails is really great! -- 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 -~----------~----~----~----~------~----~------~--~---