0

I have page consisting of a calendar view ( http://code.google.com/p/calendardateselect/ ) as well as divs, each of which contain information about a person. In each div I want to have a link to a new controller and action, and pass the id for the person and the date selected in the calendar.

I can think of a one way, but I'm thinking there's likely a better solution:

1) Do something like:

=link_to_function "Week", "weekClicked(#{person.id})"

Then in the weekClicked() javascript method I get the selected date from the calendar, such as:

$('e_date').selected_date;

then with javascript I could make a post request as mentioned here: JavaScript post request like a form submit

2) Or, is there a way that I could make each link a button in it's own form and maybe have a hidden field that gets the selected date from the calendar as or before the form is submitted? I tried this too, but couldn't figure it out. This definitely seems like it's more on the right track than #1.

Thanks.

Community
  • 1
  • 1
99miles
  • 10,942
  • 18
  • 78
  • 123

1 Answers1

0

Hmm,

Would it be possible to just use JS to serialize the params you want to send. Store the Person.id in a hidden field var person_id = '<%= person.id %>'

Now for you buttons/links you can just call the functions like weekClicked(person_id);

where

weekClicked = function(person_id) {
  var data = $('#calendar').serialize() + '&' + $('other_var').serialize;
  doAjaxCall(data);
}

You can chain all the necessary inputs from the page to the data variable above. I am assuming JQuery but there will be similar options in other libs.

Will
  • 8,102
  • 5
  • 30
  • 32