itmammoth / rails_sortable

Easy drag & drop sorting with persisting the arranged order for rails
MIT License
142 stars 37 forks source link

Relative app url #42

Open dostapn opened 4 years ago

dostapn commented 4 years ago

I have root url as /somepath/APP At plugin.js we have this code:

(function($) {
  $.fn.railsSortable = function(options) {
    options = options || {};
    var settings = $.extend({}, options);
    settings.update = function(event, ui) {
      if (typeof options.update === 'function') {
        options.update(event, ui);
      }
      $.ajax({
        type: 'POST',
        url: '/sortable/reorder',
        dataType: 'json',
        contentType: 'application/json',
        data: JSON.stringify({
          rails_sortable: $(this).sortable('toArray'),
        }),
      });
    }
    this.sortable(settings);
  };
})(jQuery);

need to set variable to url or get it after app initialization.

skillmatic-co commented 1 year ago

+1

@itmammoth I need something similar, my app lives in Shopify so the AJAX needs to hit at the app proxy URL, not the current window's URL. Is there a way to set the base URL for the AJAX calls?

skillmatic-co commented 1 year ago

Thanks @itmammoth, this solved my issue.

@dostapn I assume this would fix your issue as well.

Edit: This solved my issue but did have to update some cors policies in my Rails app. Something along these lines that would be nice in the future is to be able to scope/modify the route. Again, in my Shopify instance, my app lives at /app_proxy/ so, making the route be scoped to 'app_proxy' would have been nice. This would have solved my issue without updating any cors policies.