Newbie in ROR need help about its javascript

hello, i’m a newbie using ROR.
i have this function below inside my public/application.js and i’m
wondering whether i can replace “San Fransisco” and “New York” in this
command “setDirections(“San Francisco”, “New York”, “en_US”);” with
session[:address1] and session[:address2]…???
Please can anyone show me how to do it…
"
function initialize() {
if (GBrowserIsCompatible()) {
alert(“kyaaaaaaaa”)

    map = new GMap2(document.getElementById("map_canvas"));
    gdir = new GDirections(map,

document.getElementById(“directions”));
GEvent.addListener(gdir, “load”, onGDirectionsLoad);
GEvent.addListener(gdir, “error”, handleErrors);
setDirections(“San Francisco”, “New York”, “en_US”);
}
}
"

On Fri, Apr 11, 2008 at 3:13 PM, Adi [email protected] wrote:

hello, i’m a newbie using ROR.
i have this function below inside my public/application.js and i’m
wondering whether i can replace “San Fransisco” and “New York” in this
command “setDirections(“San Francisco”, “New York”, “en_US”);” with
session[:address1] and session[:address2]…???
Please can anyone show me how to do it…

One way (not the DRYest or most maintainable, but definately the
simplest and it will get you going) is in your view.html.erb file you
can put:

<% if session[:address1] -%>

<% end -%>

And then take it out of application.js

Regards

Mikel

Thanks a lot Mikel… But now i really can’t try whether it’s working
or not… I think there’s something wrong with my internet connection
now… after i see you code, i’m wondering, if it’s possible to write
the code inside the application.js file like this code below :
"
function initialize() {
if (GBrowserIsCompatible()) {
alert(“kyaaaaaaaa”)

    map = new GMap2(document.getElementById("map_canvas"));
    gdir = new GDirections(map,

document.getElementById(“directions”));
GEvent.addListener(gdir, “load”, onGDirectionsLoad);
GEvent.addListener(gdir, “error”, handleErrors);
setDirections(<%= session[:address1] -%>, <%= session[:address2] -%>,
“en_US”);
}
}
"

Regards

Adi

On 11 Apr 2008, at 08:45, Adi wrote:

   map = new GMap2(document.getElementById("map_canvas"));
   gdir = new GDirections(map,

document.getElementById(“directions”));
GEvent.addListener(gdir, “load”, onGDirectionsLoad);
GEvent.addListener(gdir, “error”, handleErrors);
setDirections(<%= session[:address1] -%>, <%= session[:address2] -%>,
“en_US”);
}
}
"

application.js isn’t passed through erb, so no.
If I were you I’d make that initialize function take the 2 addresses
as its arguments and call it from somewhere where you do have access
to the session.

Fred

Thanks for the information Fred, i’m just confused from where i can
access the session…?? I still can’t try the Mikel’s solution, cause
i think there are troubles with my internet connection…

Regards,

Adi

On Mon, Apr 14, 2008 at 12:48 PM, Adi [email protected] wrote:

Mikel, I’ve tried what you suggested me to do. And the result is i got
an unknown error. After a few trial, i know that if i replace
“setDirections(”<%= session[:address1] -%>", “<%= session[:address2] -
%>”, “en_US”);" with fixed command such as “setDirections(“new york”,
“boston”, “en_US”);” then the error will never showed up… In my
opinion, the setDirections function, somehow did not passing the right
parameters…

Where did you put that javascript? In the view template? Or in
application.js?

Mikel

Mikel, I’ve tried what you suggested me to do. And the result is i got
an unknown error. After a few trial, i know that if i replace
“setDirections(”<%= session[:address1] -%>", “<%= session[:address2] -
%>”, “en_US”);" with fixed command such as “setDirections(“new york”,
“boston”, “en_US”);” then the error will never showed up… In my
opinion, the setDirections function, somehow did not passing the right
parameters…

If you don’t mind, would you share me any opinion…

Regards,

Adi

i put only initialize function in the view template and the other
function i put them in application.js…

Adi

On Mon, Apr 14, 2008 at 7:33 PM, Adi [email protected] wrote:

i put only initialize function in the view template and the other
function i put them in application.js…

Well, the <%= -%> parts have to be in your view template. They can
not be in the application.js.

The <%= -%> contains ruby code that will only get executed if it is in
an ERB template.

Regards

Mikel

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs