Max Williams
2007-Jul-24 14:06 UTC
set a rails variable to the output of a javascript function?
I have a javascript function that outputs a string. In my rhtml view file, i want to set a rails variable to the output from this function? Can anyone tell me how to set this up please? -- 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 -~----------~----~----~----~------~----~------~--~---
JAWspeak
2007-Jul-25 05:32 UTC
Re: set a rails variable to the output of a javascript function?
Ajax should do it, right? Do one of the ajax calls posting that variable back On Jul 24, 10:06 am, Max Williams <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have a javascript function that outputs a string. In my rhtml view > file, i want to set a rails variable to the output from this function? > Can anyone tell me how to set this up please? > -- > 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 -~----------~----~----~----~------~----~------~--~---
Rene Retz
2007-Sep-27 02:30 UTC
Re: set a rails variable to the output of a javascript function?
Do you have links with examples? Is therre another way to do that? I would like to do that inside a rails call. Thanks René On 7/25/07, JAWspeak <jawolter-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Ajax should do it, right? > > Do one of the ajax calls posting that variable back > > On Jul 24, 10:06 am, Max Williams <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > I have a javascript function that outputs a string. In my rhtml view > > file, i want to set a rails variable to the output from this function? > > Can anyone tell me how to set this up please? > > -- > > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten
2007-Sep-27 11:50 UTC
Re: set a rails variable to the output of a javascript function?
Javascript is client-side, ruby/rails is server side. The only way for the 2 to exchange values or anything else for that matter, is by sending requests to and replying back, either by ajax or a normal request. you cant run javascript in the view before it''s sent to the browser, as well as you cant run ruby in the browser, only on the server side. On 27 Sep., 04:30, "Rene Retz" <rene.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Do you have links with examples? > > Is therre another way to do that? I would like to do that inside a rails > call. > > Thanks > René > > On 7/25/07, JAWspeak <jawol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Ajax should do it, right? > > > Do one of the ajax calls posting that variable back > > > On Jul 24, 10:06 am, Max Williams <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > I have a javascript function that outputs a string. In my rhtml view > > > file, i want to set a rails variable to the output from this function? > > > Can anyone tell me how to set this up please? > > > -- > > > Posted viahttp://www.ruby-forum.com/.- 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 -~----------~----~----~----~------~----~------~--~---
Rene Retz
2007-Sep-27 18:37 UTC
Re: set a rails variable to the output of a javascript function?
Thorsten, Thaks for response, I understand. But I am sending a view to browser from server with a javascript. This javascript will have some actions interacting with the user and than when user send a new request to control I would like to send with a string processed throw javascript. The problem is that I don''t kwon how to put string returned from a javascript call function inside an Form_tag. I would like something like it: <% form_tag :action => ''create'', :mystring => foo.bar() do %> <%= submit_tag "Create" %> <% end %> foo is my javascript object. Thanks again! Rene On 9/27/07, Thorsten <duplexxx-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > > Javascript is client-side, ruby/rails is server side. The only way for > the 2 to exchange values or anything else for that matter, > is by sending requests to and replying back, either by ajax or a > normal request. you cant run javascript in the view before it''s sent > to the browser, as well as you cant run ruby in the browser, only on > the server side. > > On 27 Sep., 04:30, "Rene Retz" <rene.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Do you have links with examples? > > > > Is therre another way to do that? I would like to do that inside a rails > > call. > > > > Thanks > > René > > > > On 7/25/07, JAWspeak <jawol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > > Ajax should do it, right? > > > > > Do one of the ajax calls posting that variable back > > > > > On Jul 24, 10:06 am, Max Williams <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > > wrote: > > > > I have a javascript function that outputs a string. In my rhtml > view > > > > file, i want to set a rails variable to the output from this > function? > > > > Can anyone tell me how to set this up please? > > > > -- > > > > Posted viahttp://www.ruby-forum.com/.- 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 -~----------~----~----~----~------~----~------~--~---
Bob Showalter
2007-Sep-27 19:23 UTC
Re: set a rails variable to the output of a javascript function?
On 9/27/07, Rene Retz <rene.retz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thorsten, > > Thaks for response, > > I understand. > But I am sending a view to browser from server with a javascript. This > javascript will have some actions interacting with the user and than when > user send a new request to control I would like to send with a string > processed throw javascript. > The problem is that I don''t kwon how to put string returned from a > javascript call function inside an Form_tag. > I would like something like it: > > <% form_tag :action => ''create'', :mystring => foo.bar() do %> > <%= submit_tag "Create" %> > <% end %> > > foo is my javascript object.I think the simplest way to do something like this is to create a hidden field in the form and have your javascript function put its value into that field so it gets passed as part of the request. If your function needs to be run just as the form is submitted, you can hook it into the onsubmit event. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rene
2007-Sep-29 02:57 UTC
Re: set a rails variable to the output of a javascript function?
Could you give me an example? On 27 set, 16:23, "Bob Showalter" <showa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 9/27/07, Rene Retz <rene.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Thorsten, > > > Thaks for response, > > > I understand. > > But I am sending a view to browser from server with a javascript. This > > javascript will have some actions interacting with the user and than when > > user send a new request to control I would like to send with a string > > processed throw javascript. > > The problem is that I don''t kwon how to put string returned from a > > javascript call function inside an Form_tag. > > I would like something like it: > > > <% form_tag :action => ''create'', :mystring => foo.bar() do %> > > <%= submit_tag "Create" %> > > <% end %> > > > foo is my javascript object. > > I think the simplest way to do something like this is to create a > hidden field in the form and have your javascript function put its > value into that field so it gets passed as part of the request. If > your function needs to be run just as the form is submitted, you can > hook it into the onsubmit event.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
tonypm
2007-Oct-02 07:17 UTC
Re: set a rails variable to the output of a javascript function?
1. To write to a form field using javascript in the page use: document.repair_form.repair_customer_id.value= 45 where in my case: repair_form is the name of the form and customer_id is the name of the field. 2. Another way to update the server with a js value is to pass it via a call to remote. ie. create a new ajax call passing in the js variable you want to send. eg. <script type="text/javascript"> //<![CDATA[ function update_customer(customer_id) { new Ajax.Request(''/repair/change_customer/''+customer_id, {asynchronous:true, evalScripts:true}) } var external_update_customer = this.update_customer //]]> </script> now I can call this from js code and the value I pass can be obtained from the params[:id] on the server side. ie. update_customer(67) will cause an asynchronous call to change_customer method in repair controller with params[:id] of 67. I prefer doing it this way and then updating the page fields from the server render :update response. You can do server side checking that way and update other things like error prompts etc. Incidentally to directly update the field from the server response you can do: render :update do |page| page<<"document.repair_form.repair_customer_id.value#{@customer.id}" end Also, in the js snippet, I have included - var external_update_customer = this.update_customer. This allows me to call this function from a popup window. using the js opener method. So a popup window can now communicate a value back to the server via the parent window. Useful to do popup look-ups. Finally, the js SCRIPT was added to the page directly. I am currently playing with different ways of doing these sort of updates, but if I decide to use this approach, it would make sense to build a rails helper to create the js updater function. hth tonypm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---