0

Idea: I want to disable js script on specific page(e.g new_post_path), that is placed in application.js. On another page script should works. Have you any idea how to solve this problem? I thought to use loop unless current_page?(new_post_path), but it's not work in js file.

Simple script to disable:

  window.setTimeout(function() {
      $(".alert").fadeTo(500, 0).slideUp(500, function() {
          $(this).remove();
      });
  }, 10000);
end

1 Answer 1

2

You could set two attributes in the layout:

<body data-controller="<%= controller_name %>" data-action="<%= action_name %>">

</body>

and from your js, check the value of data-controller and data-action to know whether or not you want to run the script on that action.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.