P
P
Pavel Grudinkin2016-08-19 22:19:50
Ruby on Rails
Pavel Grudinkin, 2016-08-19 22:19:50

Why doesn't js.erb file run on subdomain?

I made a modal window in the form of a partial, i.e. got two files like "_modal.html.haml" and "modal.js.erb". On all pages without a subdomain, the JS code works, but not on any subdomain, although I see in the logs that everything was rendered in the same way as in the first case.
Where to look for a problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Grudinkin, 2016-08-19
@Hunt666

Method 1 (CSRF danger):
config/application.rb:

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

Method 2 (which I used at home): I added a render of the modal window partial to the layouts of the required pages. The js code from js.erb moved the code of the corresponding pages to js. I made a 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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question