Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Just want to change button text on-click. Coffeescript not making any sense to me.

Javascript • Asked by NicWickman
Hey guys, trying to do a pretty simple thing but all the information I can find online (for "beginners") seems to omit some core things I'm expected to know, because it doesn't even do so much as throw an error. Rails 5.2

I just want to change the text of my button on click.

I have a standard button_to
    <%= button_to "Unsave", resource_path(id:, remote: true, method: :delete, class: "save_btn", id: "save_btn"%>

I have saved the following to "" in my javascripts folder
$ ->
  $(".save_btn").on "ajax:success", (e, data, status, xhr) ->

In my application.html.erb layout I am loading my JS
    <script src="//"></script>
    <%= stylesheet_link_tag    'application', media: 'all',
                                              'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'resources', 'data-turbolinks-track': 'reload' %>

Rails threw me an error and instructed me to insert this into assets.rb, which I have done
Rails.application.config.assets.precompile += %w( resources.js )

Nothing happens to the button when I click it. Can somebody please fill in the blanks for me? I have no javascript experience and I am pretty sure I am missing something to the equivalent of "Is it plugged in?".

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 29,763+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.