How to run Javascript function on the Current page through the Application Controller?

Asked

Viewed 240 times

2

I’m doing a browser validation (IE < 10) through the Application Controller with the gem "browser". I need any application page that is accessed to run a Javascript function with a message saying that the browser is not recommended.

Any idea, suggestion or other way to do it dynamically?

Code:

class ApplicationController < ActionController::Base
  before_action :is_ie_browser?

  def is_ie_browser?
    if browser.ie? && browser.version.to_i < 10
      #executar uma funcao
    end
  end
end

1 answer

1

  • Blz @Alextakitani, thank you! I had already gone through this solution, but I wanted something more automatic, I have several layouts and some have js files that others do not have. In that case I would have to go through all of them and add the file with Function. I am also not using application.js in some layouts

  • Jefferson, you should use the application in all layouts. Taking out you lose the advantages of the pipeline Asset.

  • Agree @Alextakitani, but in some layouts was generating some conflicts.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.