How to transfer a javascript value into a symbol used in Ruby on Rails

Hi,

I am currently using Rails 2.0.2 with Ruby 1.8.7. My Prototoype.js version is 1.7(if required). I am basically trying to integrate the calendar_date_select plugin in my app.

The link/tutorial I am referring is: http://ianli.com/site/HowTo/UseCalendarDateSelectRailsPlugin

I am trying to save the date I receive through the date select plugin and store in a rails symbol :publishing_date.

I am selecting the date using the calendar_date_select plugin. The selected date gets uploaded into the text field, but I am not sure how to transfer that returned value onto my publishing_date attribute(:publishing_date symbol) of my books table.

On manually entering a date I am able to see it reflected in the DB. I am getting stuck when I am trying to save it through the plugin.

       <%= f.text_field :publishing_date %>

On clicking on the create button I get a null value for the date selected via the calendar_date_select plugin. I am able to properly insert values for name of book and author.

My code for a new book looks like this:

An interesting excerpt from the aforementioned tutorial link is given below:

The value of the selected date can be accessed by getting the value

of the text field named calendar.

Using the Prototype Javascript Library, you can do the following to

get the value.

$F\(&#39;calendar&#39;\)

The roadblock I am facing is how to call the `$F('publishing_date')` in my new.html.erb file using the rails `<%=>` tag and then assign that to my :publishing_date symbol which will eventually be use to update the publishing_date attribute in my books table.

You can't. Javascript is client side <%= is server side. You don't need to though. When the form containing the calendar gets submitted, there will be a calendar parameter (the first argument passed controls the name).

Fred

Frederick Cheung wrote in post #979492:

The roadblock I am facing is how to call the `$F('publishing_date')` in my new.html.erb file using the rails `<%=>` tag and then assign that to my :publishing_date symbol which will eventually be use to update the publishing_date attribute in my books table.

You can't. Javascript is client side <%= is server side. You don't need to though. When the form containing the calendar gets submitted, there will be a calendar parameter (the first argument passed controls the name).

Fred

HI Fred,

If I can't call the `$F('publishing_date')`, how else do you think can I assign the calendar parameter value to the :publishing_date symbol such that the value is then stored in the database on submitting via the create button. It's taking a NULL value currently and not the value selected via the plugin date interface.

Thanks for your time..

Mohnish

hey, i would suggest two checks - -check of published date column to be of the type datetime. - check your log files for parameters beimg sent after submitting new book form. in your case date shpuld be sent as book[published_date]

i am sure second check should help.

Frederick Cheung wrote in post #979492:

>> The roadblock I am facing is how to call the `$F('publishing_date')` in >> my new.html.erb file using the rails `<%=>` tag and then assign that to >> my :publishing_date symbol which will eventually be use to update the >> publishing_date attribute in my books table.

> You can't. Javascript is client side <%= is server side. You don't > need to though. When the form containing the calendar gets submitted, > there will be a calendar parameter (the first argument passed controls > the name).

> Fred

HI Fred,

If I can't call the `$F('publishing_date')`, how else do you think can I assign the calendar parameter value to the :publishing_date symbol such that the value is then stored in the database on submitting via the create button. It's taking a NULL value currently and not the value selected via the plugin date interface.

According to the examples at http://2007.electronicholas.com/calendar, you can do calendar_date_select_tag :publishing_date

Fred

ratnadeepdeshmane@gmail.com wrote in post #979552:

hey, i would suggest two checks - -check of published date column to be of the type datetime. - check your log files for parameters beimg sent after submitting new book form. in your case date shpuld be sent as book[published_date]

i am sure second check should help.

need to though. When the form containing the calendar gets submitted,

create button. It's taking a NULL value currently and not the value -- 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@googlegroups.com. 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.

-- Ratnadeep Deshmane. http://rtdptech.com

Hi Ratna,

Thanks for your reply,

The publishing_date variable is of type "date" and not "datetime", I just observed that the built in attributes(like created_at,updated_at) are of type "datetime". Could you please tell me how would this make a difference or how could it impact the value retrieved from the plugin which will be eventually stored in the DB.

Frederick Cheung wrote in post #979561:

> Fred

Hi Fred,

it doesn't work. I have tried it out earlier also.

What happens? What do the parameters look like in the log file?

Fred

Hi Fred,

I am really sorry for replying late..

In the parameters wrt the development.log for books doesn't consider publishing_date to be as part of books.

Have a look at this:

Processing BooksController#create (for 127.0.0.1 at 2011-02-07 13:39:33) [POST]   Session ID: BAh7BzoMY3NyZl9pZCIlZWI5YTUwYzBjY2E1NDdhNGI3OTc2M2YyNWFkZDkw%0AMGIiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh%0Ac2h7AAY6CkB1c2VkewA%3D--0abacbbecbc5fbb17e945b639dcbbe7f7520532a   Parameters: {"commit"=>"Create", "authenticity_token"=>"8265666eb9501a997981c9c35c6ebc296b0d21b7", "action"=>"create", "publishing_date"=>"February 12, 2011", "controller"=>"books", "book"=>{"title"=>"abcd8", "author"=>"defg8"}}   Book Columns (0.001384) SHOW FIELDS FROM `books`   SQL (0.000088) BEGIN   Book Create (0.000392) INSERT INTO `books` (`created_at`, `author`, `title`, `updated_at`, `publishing_date`) VALUES('2011-02-07 13:39:33', 'defg8', 'abcd8', '2011-02-07 13:39:33', NULL)   SQL (0.001896) COMMIT Redirected to http://localhost:3000/books/1054583410 Completed in 0.01805 (55 reqs/sec) | DB: 0.00376 (20%) | 302 Found [http://localhost/books\]

I had a question, is it because that the calendar_date_select plugin takes the date in the format "Month dd, year" and not as of the standard attributes like created_at which take "year-month-date", there is a null being inserted for publishing_date while creating a new books record?

Thanks

Mohnish

Hi Fred,

I am really sorry for replying late..

In the parameters wrt the development.log for books doesn't consider publishing_date to be as part of books.

Have a look at this:

Processing BooksController#create (for 127.0.0.1 at 2011-02-07 13:39:33) [POST] Session ID: BAh7BzoMY3NyZl9pZCIlZWI5YTUwYzBjY2E1NDdhNGI3OTc2M2YyNWFkZDkw%0AMGIiCmZsYXNo SUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh%0Ac2h7AAY6CkB1c2VkewA%3D-- 0abacbbecbc5fbb17e945b639dcbbe7f7520532a Parameters: {"commit"=>"Create", "authenticity_token"=>"8265666eb9501a997981c9c35c6ebc296b0d21b7", "action"=>"create", "publishing_date"=>"February 12, 2011", "controller"=>"books", "book"=>{"title"=>"abcd8", "author"=>"defg8"}} Book Columns (0.001384) SHOW FIELDS FROM `books` SQL (0.000088) BEGIN Book Create (0.000392) INSERT INTO `books` (`created_at`, `author`, `title`, `updated_at`, `publishing_date`) VALUES('2011-02-07 13:39:33', 'defg8', 'abcd8', '2011-02-07 13:39:33', NULL) SQL (0.001896) COMMIT Redirected tohttp://localhost:3000/books/1054583410 Completed in 0.01805 (55 reqs/sec) | DB: 0.00376 (20%) | 302 Found [http://localhost/books\]

I had a question, is it because that the calendar_date_select plugin takes the date in the format "Month dd, year" and not as of the standard attributes like created_at which take "year-month-date", there is a null being inserted for publishing_date while creating a new books record?

It's because the publishing_date parameter is being sent at the top level (ie params[:publishing_date], much as if you'd written text_field_tag 'publishing_date'. Either change the name to 'book[publishing_date]' or I seem to recall there is another form of the helper (analogous to text_field) that does that for you

Fred

Frederick Cheung wrote in post #980025:

[POST] 'defg8', 'abcd8', '2011-02-07 13:39:33', NULL) SQL (0.001896) COMMIT Redirected tohttp://localhost:3000/books/1054583410 Completed in 0.01805 (55 reqs/sec) | DB: 0.00376 (20%) | 302 Found [http://localhost/books\]

I had a question, is it because that the calendar_date_select plugin takes the date in the format "Month dd, year" and not as of the standard attributes like created_at which take "year-month-date", there is a null being inserted for publishing_date while creating a new books record?

It's because the publishing_date parameter is being sent at the top level (ie params[:publishing_date], much as if you'd written text_field_tag 'publishing_date'. Either change the name to 'book[publishing_date]' or I seem to recall there is another form of the helper (analogous to text_field) that does that for you

Fred

Hi Fred,

Good idea:), I didn think of it.. but..

I am able to now get publishing_date in my parameters for book by using 'book[publishing_date]'. But while inserting it inserts a null value still.

I figured another way to tackle my issue which worked, In the controller of books , I gave @book.publishing_date = params[:publishing_date], this would take the publishing_date at the top level and assign it wrt a particular book in the controller create action/method.