Getting Javascript to talk to Rails

Hi guys!

I was wondering on how to save data from a javascript function to rails.
It would great if someone could me help me out!

cheers!

On Dec 15, 2:52 pm, Serkan S. [email protected]
wrote:

Hi guys!

I was wondering on how to save data from a javascript function to rails.
It would great if someone could me help me out!

You’ll need to make an ajax request. You should be able to draw some
inspiration from the remote_function rails helper (which will
generate the right bit of js that you can then reuse).

Fred

Thanks Fred! im gonna look into it!

Hey there guys! Still having problems with javascript with Rails! Heres
my problem simplified (btw I know it doesn’t work! >_< ):

<%= @localVariable = javascript_tag (“hello(‘hi serkan!’)” %>
<%= javascript_tag(remote_function(:update => :ajax_call,
:url => { :controller => ‘login’,
:action => :get_string },
:with => “'InputVariable=” + @localVariable + “’”)) %>

So Im trying to get some data from a javascript function into rails, but
I just cant figure it out. Any help would save me from killing myself
and would be gratefully appreciated!

thanks!

serkan

I beg someone to help… i cant move forward without knowing how to do
this… ;_;

:onchange=>remote_function(:url =>{:action => ‘Yr_action’},:with =>
“‘id=’+this.value”, :method=>:post)

with this logic u can carry out things…

:with is to pass the value to rails method using java script…
this patch i used in select tag so in ;with is used this.value u change
as per yr need.

with :action u can call a rails method in yr controller…

Frederick! Where are you?!

instead onchange u can have any function as per yr need…
try it out…

Thanks for replying Ratnavel! You’re a stud!!

:onchange=>remote_function(:url =>{:action => ‘Yr_action’},:with =>
“‘id=’+this.value”, :method=>:post)

One question! Instead of using a form element e.g."‘id=’+this.value",
can i do this:

:onchange=>remote_function(:url =>{:action => ‘Yr_action’},:with =>
“‘id=’+name”, :method=>:post)

thanks again!

Refer api…

http://rails.rubyonrails.com/

:with is explained clearly in method Observe_field

thanks Ratnavel! Im gonna look into it!

no luck…im still stuck :frowning:

The reason why you’re not getting a reply is because people ignore short
replies like “no luck… im still stuck :-(”.

Explain how you’re stuck, what exactly you’re trying to accomplish in
just
the right amount of detail.

On Dec 28, 2007 5:02 AM, Serkan S.
[email protected]
wrote:

no luck…im still stuck :frowning:

Posted via http://www.ruby-forum.com/.


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.