Made a modal window in the form of a partial, i.e. got two files of the form "_modal.html.haml" and "modal.js.erb". On all pages without a subdomain, the JS code works, on any subdomain, although I see in the logs that everything has been rendered the same way as in the first case.

Where to look for a problem?

  • 2
    In the browser console? - D-side
  • @ D-side, In the console, in the protection tab, I see "The request from an external source is blocked: The policy of one source prohibits the reading of a remote resource. (Reason: the CORS header is not 'Access-Control-Allow-Origin')." Now I understand where to dig. - Tiazar

1 answer 1

Method 1 (as suggested by the dangerous):

config / application.rb:

config.action_dispatch.default_headers.merge!({ 'Access-Control-Allow-Origin' => '*', 'Access-Control-Request-Method' => '*' }) 

Method 2 (which he used in himself): In the layouts of the necessary pages, added a render of the partial modal window. Js code from js.erb rendered the code for the relevant pages in js. Made the second route to the desired action, it turned out something like this:

 constraints(Subdomain) do post 'action_second/create', to: 'controller#create' end constraints :subdomain => '' do post 'action_first/create', to: 'controller#create' end 

PS

 class Subdomain def self.matches?(request) request.subdomain.present? end end 
  • one
    Well, in general it is dangerous , because it opens for CSRF. - D-side