All threads / Is possible to check boolean value by JS?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Is possible to check boolean value by JS?

Dmitry Amelchenko asked in Javascript

In Rails 4 app i need to implement bootstrap modal when user comes for first time and accept the terms.
I'm trying to do something like this:
application.html.haml

...
= content_tag :body, data: { accept_terms: current_user.accept_terms? } do
...

current_user.accept_terms? - just instance method returns true or false
main.js.coffee

...
$(document).on 'page:change', ->
return unless $('body').data('accept-terms')
$('.terms-modal').modal 'show'
...

Yep, something like that could work. That should print out true or false in the data attribute (you can inspect the html to verify) and sure give you back a Javascript boolean you can use when you query for it.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 39,609+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.