Matthieu Ruiz
2008-Feb-24 12:23 UTC
[Facebooker-talk] Call a javascript function from a controller
Hi, I don''t really understand if it''s possible to call a javascript function from a rails controller. For instance, I want to update my view when someone submit my form and after I checked it was valid. ( puts a "<fb:success message=\"Changes saved.\" />" in my case). def save # I do all my verifications... render :update do |page| page.call "my_javascript_function" # Or with facebook id : page.call "aXXXXXXXX_my_javascript_function" end end Is there a way to do it ? Thanks a lot, I''m a bit lost :S Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/facebooker-talk/attachments/20080224/5af4e493/attachment.html
Heavy Sixer
2008-Feb-24 14:13 UTC
[Facebooker-talk] Call a javascript function from a controller
Matt, You need to read up on respond_to blocks it takes a .js argument to be used when a page requests a javascript return object. You can then use something like an rjs template to update the page that called it through something like an ajax event. Mark On Feb 24, 2008, at 6:23 AM, Matthieu Ruiz wrote:> Hi, > > I don''t really understand if it''s possible to call a javascript > function from a rails controller. > For instance, I want to update my view when someone submit my form > and after I checked it was valid. ( puts a "<fb:success message= > \"Changes saved.\" />" in my case). > > def save > # I do all my verifications... > render :update do |page| > page.call "my_javascript_function" > # Or with facebook id : page.call > "aXXXXXXXX_my_javascript_function" > end > end > > Is there a way to do it ? > Thanks a lot, I''m a bit lost :S > > Matt > > _______________________________________________ > Facebooker-talk mailing list > Facebooker-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/facebooker-talk
Joel Nylund
2008-Feb-24 15:43 UTC
[Facebooker-talk] Call a javascript function from a controller
I could be wrong, but I dont think the rjs stuff works out of the box with facebook. Mike is working on a facebook specific link_to_remote that will be the simplest way to do this , but until then you can do it yourself. see http://jnylund.typepad.com/joels_blog/2008/02/ajax-rails-face.html for some examples of how to do ajax/js stuff in facebook. Joel On Feb 24, 2008, at 7:23 AM, Matthieu Ruiz wrote:> Hi, > > I don''t really understand if it''s possible to call a javascript > function from a rails controller. > For instance, I want to update my view when someone submit my form > and after I checked it was valid. ( puts a "<fb:success message= > \"Changes saved.\" />" in my case). > > def save > # I do all my verifications... > render :update do |page| > page.call "my_javascript_function" > # Or with facebook id : page.call > "aXXXXXXXX_my_javascript_function" > end > end > > Is there a way to do it ? > Thanks a lot, I''m a bit lost :S > > Matt > > _______________________________________________ > Facebooker-talk mailing list > Facebooker-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/facebooker-talk
David Clements
2008-Feb-24 16:21 UTC
[Facebooker-talk] Call a javascript function from a controller
If you look at Joel''s second example and wrap you javascript function call in <script> tags then your function should get called. def example2 is_checked = params[:ischecked] if is_checked == "true" txt_to_render = "<fb:success message=\"Task has been marked complete!\" /> <script> aXXXXXXXX_my_javascript_function();</script>" else txt_to_render = "<fb:success message=\"Task has been marked incomplete!\" />" end render :text => txt_to_render, :layout => false end Dave On Sun, Feb 24, 2008 at 8:43 AM, Joel Nylund <jnylund at yahoo.com> wrote:> I could be wrong, but I dont think the rjs stuff works out of the box > with facebook. Mike is working on a facebook specific link_to_remote > that will be the simplest way to do this , but until then you can do > it yourself. > > see http://jnylund.typepad.com/joels_blog/2008/02/ajax-rails-face.html > for some examples of how to do ajax/js stuff in facebook. > > Joel > > > > > On Feb 24, 2008, at 7:23 AM, Matthieu Ruiz wrote: > > > > > Hi, > > > > I don''t really understand if it''s possible to call a javascript > > function from a rails controller. > > For instance, I want to update my view when someone submit my form > > and after I checked it was valid. ( puts a "<fb:success message> > \"Changes saved.\" />" in my case). > > > > def save > > # I do all my verifications... > > render :update do |page| > > page.call "my_javascript_function" > > # Or with facebook id : page.call > > "aXXXXXXXX_my_javascript_function" > > end > > end > > > > Is there a way to do it ? > > Thanks a lot, I''m a bit lost :S > > > > Matt > > > > > > _______________________________________________ > > Facebooker-talk mailing list > > Facebooker-talk at rubyforge.org > > http://rubyforge.org/mailman/listinfo/facebooker-talk > > > _______________________________________________ > Facebooker-talk mailing list > Facebooker-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/facebooker-talk >