I have a script that takes the value of selected option in a form,
and makes a request ajax to a rails application. The ideia  will be
make a  ajax request and return a option string to populate a select.
At this moment I just made some tests,  when the prototype makes a
ajax request, this request wasn't made with post method. And the rails
didn't understood the method used by request, as you can see bellow:

The script:
<script type="text/
   // we will add our javascript code here
        var SelectSubCat = Class.create();
        SelectSubCat.prototype = {
                initialize: function(select){
                        this.category = $(select);
                        this.category.onchange =

        request_ajax: function(e){
                        new Ajax.Request("
search_sub_cat_and_return_option_to_select.json", {
parameters: {id: this.category.value},
onSuccess: function(transport){
                        var json = transport.responseText.evalJSON();

                <select name="cat" id="cat" size="0">
                                <option value="54" >Academia</option>
                                <option value="54" >Restaurante</option>
                                <option value="54" >Bares</option>
                <select name="sub" id="sub">
                                <option value="">--  Selecione Sub Categorias 

When the request was made with the ajax, the following message I see
in the console:

Started OPTIONS "/search_sub_cat_and_return_option_to_select.json" for at Sat Jul 30 12:05:54 -0300 2011
DEPRECATION WARNING: You are using the old router DSL which will be
removed in Rails 3.1. Please check how to update your routes file at:
(called from /home/emygdio/Documentos/Projetos/GuiaDF/

ActionController::RoutingError (No route matches "/

I made some test with another form post, to test the request to rails
as you can see bellow:
<form action="
search_sub_cat_and_return_option_to_select.json" method='post'>
                <select name="id" id="cat" size="0">
                                <option value="54" >Academia</option>
                                <option value="54" >Restaurante</option>
                                <option value="54" >Bares</option>
                <input type=submit>

And  the result in console was:

Started POST "/search_sub_cat_and_return_option_to_select.json" for at Sat Jul 30 12:18:31 -0300 2011
  Processing by
CatK2ItemController#search_sub_cat_and_return_option_to_select as JSON
  Parameters: {"id"=>"54"}
  CatK2Item Load (0.1ms)  SELECT `gdf_k2_categories`.* FROM
`gdf_k2_categories` WHERE `gdf_k2_categories`.`parent` = 54
"[{option:'<option value='669'>Auditores </option><option
value='670'>Contabilidade - Escritórios </option>'}]"
Completed 200 OK in 21ms (Views: 4.1ms | ActiveRecord: 0.1ms)

As can you see the rails understands properly the request, but the
ajax request didn't made the request with the correct method.
How Can I fix this?


You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to