hi guys,
I am now rewriting an existing app (rails 2.3.8) with rails 3.1.x.

As observe_field() is no longer the way to go with rails 3 when ajax
is used, I am trying to rewrite a piece of functionality for when a
select box (drop down) with a div id of 'category' is clicked
-a call is made to the sub_categories controller with the category ID
(from the selected option in the category select box)
-the sub categories belonging to the selected category ID will be
returned and a another select box is to be generated in the div with
id of 'sub_category'.

I'm looking at http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/
and I have a question now.

How do I go about passing a variable value to the javascript that
performs the asynchronous call?

For example, i have :

// Append the function to the "document ready" chain
jQuery(function($) {
// when the #search field changes
$("#category").change(function() {
// make a POST call and replace the content
$.post(<%= category_sub_categories_path %>, function(data) {

-how do I pass the category id (which is a form value) to the
-would the category_id value be valid in the jQuery call?

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.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 3 | next ›
Discussion Overview
grouprubyonrails-talk @
postedDec 31, '11 at 3:55a
activeJan 1, '12 at 4:04a

2 users in discussion

K.M.: 2 posts Leonardo Mateo: 1 post



site design / logo © 2021 Grokbase