Ask A Question

Notifications

You’re not receiving notifications from this thread.

Is possible to check boolean value by JS?

Dmitrii 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'
...
Reply

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.

Reply
Join the discussion
Create an account Log in

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

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

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