1

I am trying to perform a very simple task: Button is clicked - message is displayed (via JavaScript). Most likely I am either looking in the wrong places or going completely wrong about it but I can't find any examples that will show how to accomplish this simple task.

My js function is:

function myAlert() {
     alert ("My Message")
       }

The button_tag is:

<%= button_tag "Save Changes", :onclick => "myAlert()"%>

I would like to know how to properly call the function with button_tag, and where this function should be placed in the Rails app, e.g., application.js or some other file.

1
  • Your JS is ok. Do you want a custom message coming from the back office ? An Ajax call to the back ? Commented Oct 14, 2018 at 1:15

1 Answer 1

2

Well, You are doing it in a right way already. This is a simpler and cleaner way to code. To find javascript easily you should place your js code in assets/javascripts/[file_name] where file_name is generated on the bases of your model name by generate method of rails cli.

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.