On Sat, Dec 31, 2011 at 12:54 AM, K.M. <anexiole@gmail.com> wrote:
> 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
> (onChange),
> -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) {
> $("#results").html(data);
> });
> });
> })
>
>
>
> -how do I pass the category id (which is a form value) to the
> category_sub_categories_path??
> -would the category_id value be valid in the jQuery call?
>
This has nothing to do with Rails, this is a strictly jQuery question.
Take a look at the $.post documentation[1]
Cheers.
[1]http://api.jquery.com/jQuery.post/
--
Leonardo Mateo.
There's no place like ~
--
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.
No comments:
Post a Comment