简体   繁体   中英

Javascript executing despite ruby conditional statement

I'm having a small issue with javascript code being executed with no regards for ruby conditional statements.

Despite both pieces of JS being executed, only the right HTML balises are shown. (if notice, I'll only see <div role="notice"> and if it's the error, I'll only see <div role="alert"> but the javascript inside is definitely executed no matter what)

- if notice
  .row
    %div{role: 'notice'}
      :javascript
        toastr.success('#{notice}','Success')
      })
- if alert
  .row
    %div{role: 'alert'}
      :javascript
      $(function () {
        toastr.error('#{alert}','Error')
      })

I must be missing something obvious, but I can't seem to find what it is.

Thanks a lot for the help

Try this. I've corrected some indents.

- if notice
  .row
    %div{role: 'notice'}
      :javascript
        $(function () {
          toastr.success('#{notice}','Success')
        })

- if alert
  .row
    %div{role: 'alert'}
      :javascript
        $(function () {
          toastr.error('#{alert}','Error')
        })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM