Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > ruby and javascript

Reply
Thread Tools

ruby and javascript

 
 
anja
Guest
Posts: n/a
 
      05-17-2006
Hi,

I am working on a little ruby on rails project. I want to call a ruby
method out of the java_script code. The method takes two parameters,
which I have as javascript variables. How can I pass this javascript
variables to the ruby method?

Here is the source code of the rhtml file:

function updateMap(countryCode, city) {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
<% if GeoCoding.hasGeo(countryCode, city) then -%>
map.panTo(<%= GeoCoding.geo(countryCode, city) %>);
<% end -%>
}
}

I get the error :

undefined local variable or method `countryCode' for
#<#<Class:0xb761c578>:0xb761c4c4>

I understand why I get this error. But I have no idea how I can fix it.

Thanks,
anja

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      05-17-2006
anja wrote:
> Hi,
>
> I am working on a little ruby on rails project. I want to call a ruby
> method out of the java_script code. The method takes two parameters,
> which I have as javascript variables. How can I pass this javascript
> variables to the ruby method?
>
> Here is the source code of the rhtml file:
>
> function updateMap(countryCode, city) {
> if (GBrowserIsCompatible()) {
> var map = new GMap2(document.getElementById("map"));
> <% if GeoCoding.hasGeo(countryCode, city) then -%>
> map.panTo(<%= GeoCoding.geo(countryCode, city) %>);
> <% end -%>
> }
> }
>
> I get the error :
>
> undefined local variable or method `countryCode' for
> #<#<Class:0xb761c578>:0xb761c4c4>
>
> I understand why I get this error. But I have no idea how I can fix it.
>
> Thanks,
> anja
>


You can't call Ruby from JavaScript. JS is client side (i.e. executed
in the browser) while Ruby is server side. The Ruby code is executed
long before the client code; the browser sees only the generated
HTML/JS. If you want to do this check you need to fire off a HTTP
request to your server, have him do the work and process the result in JS.

Kind regards

robert
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ruby extension (C++) on OS X [ruby 1.8.2] and Google-Sketchup [ruby 1.8.5] Nicholas Ruby 3 01-28-2007 01:48 AM
The Ruby Edge - Digg for Ruby and Ruby On Rails roschler Ruby 0 10-15-2006 11:35 PM
ruby-talk, comp.lang.ruby, ruby-talk-google Phrogz Ruby 4 09-05-2006 08:19 PM
#!/usr/bin/ruby , #!/usr/bin/ruby -w , #!/usr/bin/ruby -T?, #!/usr/bin/ruby -T1... anne001 Ruby 1 04-23-2006 03:02 PM
[ANN] ruby-freedb, ruby-serialport, ruby-mp3info moved to Rubyforge guillaume.pierronnet@ratp.fr Ruby 0 08-31-2003 11:57 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57