Ruby in javascript

Hey Champs…

Can we write some ruby code into javascript ?

Can you guys light me?

On 30 March 2010 12:25, Hemant B. [email protected] wrote:

Hey Champs…

Can we write some ruby code into javascript ?

Do you mean that within some javascript can you use Ruby? If you mean
that then this would be difficult. The ruby code is run in the server
which is where ruby is installed. Javascript is run in the users PC
in the browser.

Colin

Colin L. wrote:

Do you mean that within some javascript can you use Ruby? If you mean
that then this would be difficult. The ruby code is run in the server
which is where ruby is installed. Javascript is run in the users PC
in the browser.

Hi Colin, only u come when i asks anybody for help … :slight_smile: Thanks.

Anyway my situation is that i have a gem installed on my machine
“calender_date_select” and i am dynamically populating the fields using
javascript… Now i also need to create a text-box with calendar with
javascript… Ordinarily, this is the way we use calendar_date_select:-
<%= calendar_date_select :abc, :def, :year_range =>
1.years.ago…1.years.since, %>

Can we write it in javascript…

On 30 March 2010 13:07, Hemant B. [email protected] wrote:

Colin L. wrote:

Do you mean that within some javascript can you use Ruby? If you mean
that then this would be difficult. The ruby code is run in the server
which is where ruby is installed. Javascript is run in the users PC
in the browser.

Hi Colin, only u come when i asks anybody for help … :slight_smile: Thanks.

Glad to be of help

Anyway my situation is that i have a gem installed on my machine
“calender_date_select” and i am dynamically populating the fields using
javascript… Now i also need to create a text-box with calendar with
javascript… Ordinarily, this is the way we use calendar_date_select:-
<%= calendar_date_select :abc, :def, :year_range =>
1.years.ago…1.years.since, %>

You can do anything you like in javascript that you can do on any web
page. What do you mean by “create a text-box with calendar”.

Colin

On 31 March 2010 06:43, Hemant B. [email protected] wrote:

how should i do this in javascript… I am little bit confused…
I have not used calendar_date_select but I imagine it is already using
javascript to do the popup. Have a look at the html of your page and
see what is there. (View, Page Source or similar in browser).

Colin

While using calendar_date_select, it appers like this … i mean usage of
this gem…

<%= calendar_date_select :abc, :def, :year_range =>
1.years.ago…1.years.since %>, it come like this

TEXT_BOX(nameabc[def]) Button

After clicking on button a calendar popups and whatever date i select
comes in the text box… So in web page i am doing it like this only but
how should i do this in javascript… I am little bit confused…

You can do anything you like in javascript that you can do on any web
page. What do you mean by “create a text-box with calendar”.

Colin

On 31 March 2010 09:04, Hemant B. [email protected] wrote:

2011]} );" alt=“Calendar”/>

How should i write this code in javascript… I tried it but fails…

I don’t understand what you mean when you say you want to write it in
javascript.

Colin

Hello,

if you define your Javascript function in your “html.erb” (and not on a
external file) you could just use <%= … %> to access ruby predefined
variables and on ruby
you would write that code in to a string and then use it.

but the calendar_date_select controle pretty much covers all the
javascript
needed for it to work…you just have to put it one the page.

regs.

Colin L. wrote:

On 31 March 2010 06:43, Hemant B. [email protected] wrote:

how should i do this in javascript… I am little bit confused…
I have not used calendar_date_select but I imagine it is already using
javascript to do the popup. Have a look at the html of your page and
see what is there. (View, Page Source or similar in browser).

Colin

Source code for line

<%= calendar_date_select :abc, :def, :year_range =>
1.years.ago…1.years.since, %>

is as:-

Calendar

How should i write this code in javascript… I tried it but fails…

On Mar 30, 12:44 pm, Colin L. [email protected] wrote:

Do you mean that within some javascript can you use Ruby? If you mean
that then this would be difficult. The ruby code is run in the server
which is where ruby is installed. Javascript is run in the users PC
in the browser.

I doubt this is what was being asked but there is a an implementation
of ruby in javascript (hotruby)

Fred

Hemant B. wrote:

Hey Champs…

Can we write some ruby code into javascript ?

Can you guys light me?

you can make a main_scripts.js.erb inside one of your views

then you can mix in ruby and JS together. The ruby will be processed
first, and then made into a static js file, then you can include that.
OR, you can do inline JS in your views (it’s yucky though :stuck_out_tongue: ). You
could also get crazy and include the Johnson gem and then get some crazy
ruby generating JS on the fly stuff.

Good luck!

~Jeremy

Thanks colin and Rui…

I made it worked… I copied the code from page source and give it to the
onclick of the text box. Earlier also, i was donig the same but a
variable was not there. So fixed it and worked like a charm…

Thanks again…

Colin L. wrote:

On 31 March 2010 09:04, Hemant B. [email protected] wrote:

2011]} );" alt=“Calendar”/>

How should i write this code in javascript… I tried it but fails…

I don’t understand what you mean when you say you want to write it in
javascript.

Colin

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