Error 400 AJAX in Rails

0

Good community. I present a problem in Rails with a route that I specify by means of AJAX which gives me an error of 400 Bad Request .

This is my way:

ruta archivo:app/views/admin/orders/_form.html.haml
.wrapper
    .wrapper-body.container
        .actions
            = link_to admin_orders_path, class: "btn-floating btn-flat tooltipped", "data-position" => "bottom", "data-tooltip" => t("keppler.actions.back") do
                = material_icon.md_18.arrow_back.css_class("md-dark")
        .wrapper-inputs
            .card
                .card-content
                    = simple_form_for [:admin, @order] do |f|
                        .row
                            = f.input :name_pro, collection: @projects, label_method: :name, value_method: :id, label: "Seleccionar Proyecto", include_blank: true
                        #activities
                            -# = f.input :name_pro
                            -# = f.input :item_pro
                            .form-actions.right
                                = f.button :submit, t("keppler.actions.save"), name: '_save'
                                = f.button :submit, t("keppler.actions.save_and_add_another"), name: '_add_other'



:javascript

      $(document).ready(function() {
        $('#order_name_pro').on('change', function() {
            $.ajax({
               url: "<%= items_options_path %>",
               type: "POST",
               data: { project_id: $(this).val() }
            });
         });
     });

And I leave the link of the code complete.

    
asked by Leonard J. Ávila S. 24.08.2017 в 04:03
source

1 answer

0

The error is because you are mixing erb with haml in the javascript of your form, specifically in this line:

url: "<%= items_options_path %>",

The <%= ... %> notation is erb , but since you are using haml it marks you an error; to fix it, change the line by haml notation:

url: "#{items_options_path}",
    
answered by 24.08.2017 / 16:40
source