jquery and ajax query in rails 3

hi people

I don't know much about ajax - jquery. And right now I need to use some functionality with them.

In a form (sales model) I have the following code:

<div>     <%= f.label :product_id, "Product" %>     <%= f.collection_select( :product_id, Product.all, :id, :name, options={} ) %>   </div>   <div>     <%= f.label :price, "Price" %>     <%= f.text_field :price %>   </div>

The idea is: when I select a "product" I want to show the price of that product automatically in the "price" text-field. I have a table where I store the price of each product.

I tried this example but didn't work Start an Online Business & Make Money Doing It | WebMonkey

Hope you can help me, thanks

Why would you think prototype code would work in a jquery app? What version of rails are you using? What have you done to setup your app for jquery? Why did you think that information was unnecessary? Aren't you aware that rails changes every week?

Why would you think prototype code would work in a jquery app?

I tried the example in an app with prototype (not jquery), but it didn't work, that's the reason I'm looking for a jquery way

What version of rails are you using?

Version 3.0.9

What have you done to setup your app for jquery?

I've installed jquery-rails gem

Why did you think that information was unnecessary?

I didn't, I've made a mistake, sorry

Aren't you aware that rails changes every week?

I know rails changes, but I didn't know it changes that often!!.

Can you post the your form tag?

jQuery:

No gem needed. Copy the rails.js file here:

https://github.com/rails/jquery-ujs/blob/master/src/rails.js

and put it the public/javascripts directory. Name the file jquery.rails.js. Note how the javascript_include_tag below links to that file:

app/views/layouts/application.htm.erb:

<!DOCTYPE html> <html> <head>   <title><%= @title %></title>   <%= csrf_meta_tag %>   <%=     javascript_include_tag(       "http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js&quot;,       "jquery.rails.js"     )   %>

<script type="text/javascript">   $(document).ready(function () {

      $("#sale_product_id").change(function() {         var product_id = $(this).val();             //this is equal to the html element             //$(this) turns the html element into a jquery object             //jquery objects have a val() method, which sets or             //gets the value attribute of an html element

        var query_string = "product_id=" + product_id;

        $.get('get_price/', //action name               query_string, //e.g "product_id=3"               function(data){ $("#sale_price").val(data)                   //data equals what the get_price action returns         });       });   });

</script>

.. ...

app/controllers/sales_controller.rb

class SalesController < ApplicationController

  def do_stuff     @sale = Sale.new     @products = Product.all   end

  def get_price     @price = Product.find(params[:product_id]).price     render :text => @price   end

end

app/models/sale.rb:

# == Schema Information