HAML error using ternary operator in a mailer response

248 views
Skip to first unread message

Matt Martini

unread,
Dec 15, 2011, 12:35:00 PM12/15/11
to ha...@googlegroups.com
I'm getting a HAML error when I try to use the ternary operator in a mailer response.

I have a mailer notifier that returns a form submission via email.  I want to pretty up the output so that 
the response of the radio_button :erected (which returns true or false) would be 'yes' or 'no,' respectively.

Using: 

    = ( #{@qmessage.erected} == true ) ? 'Yes' : 'No'

produces the error below.  I also tried it with "-" instead of "=".


I suspect this might be a bug as I don't have any semi-colons in my haml and yet the error message complains about an unexpected one.

Please let me know if my syntax is wrong or this is a bug.

Matt


rails (3.1.1)
haml (3.1.4)
sass (3.1.11)
sass-rails (3.1.5)
compass (0.12.alpha.0)

   SyntaxError in Quote#create

Showing .../app/views/qnotifier/quote_request.html.haml where line #39 raised:

.../app/views/qnotifier/quote_request.html.haml:39: syntax error, unexpected ';', expecting ')'
));}\n      </div>\n    </fields...
   ^
.../app/views/qnotifier/quote_request.html.haml:39: unknown regexp options - fldt
.../app/views/qnotifier/quote_request.html.haml:39: syntax error, unexpected $undefined
...n      </div>\n    </fieldset>\n  </li>\n  <br>\n</ol>\n", -...
...                               ^
.../app/views/qnotifier/quote_request.html.haml:39: unknown regexp option - l
.../app/views/qnotifier/quote_request.html.haml:39: syntax error, unexpected $undefined
...ldset>\n  </li>\n  <br>\n</ol>\n", -4, false);::Haml::Util.h...
...                               ^
.../app/views/qnotifier/quote_request.html.haml:39: unterminated string meets end of file
.../app/views/qnotifier/quote_request.html.haml:39: syntax error, unexpected $end, expecting '}'

Extracted source (around line #39):

36:         Will the equipment need to be erected?
37:       .field
38:         = ( #{@qmessage.erected} == true ) ? 'Yes' : 'No'
39:   %br

Trace of template inclusion: app/views/qnotifier/quote_request.html.haml



   SyntaxError in Quote#create

Showing .../app/views/qnotifier/quote_request.html.haml where line #39 raised:

.../app/views/qnotifier/quote_request.html.haml:39: syntax error, unexpected keyword_ensure, expecting ')'
...:Util.html_safe(_erbout);ensure;@haml_buffer = @haml_buffer....
...                               ^
.../app/views/qnotifier/quote_request.html.haml:39: syntax error, unexpected keyword_end, expecting ')'
...uffer.upper if @haml_buffer;end;
...                               ^
.../app/views/qnotifier/quote_request.html.haml:42: syntax error, unexpected keyword_end, expecting ')'

Extracted source (around line #39):

36:         Will the equipment need to be erected?
37:       .field
38:         - ( #{@qmessage.erected} == true ) ? 'Yes' : 'No'
39:   %br

Trace of template inclusion: app/views/qnotifier/quote_request.html.haml


Anoop Ranganath

unread,
Dec 15, 2011, 12:49:48 PM12/15/11
to ha...@googlegroups.com
I think this should be:

= @qmessage.erected == true ? 'Yes' : 'No'

I'm not sure why you're using the string interpolation #{} here.

Anoop

--
You received this message because you are subscribed to the Google Groups "Haml" group.
To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.

Matt Martini

unread,
Dec 15, 2011, 1:46:40 PM12/15/11
to ha...@googlegroups.com
Anoop,

= @qmessage.erected == true ? 'Yes' : 'No'
doesn't throw an error, but it does not return the correct response.

Yes is checked on the submitted form:

HAML:
      .field
        #{@qmessage.erected}
        %br
        @qmessage.erected
        %br
        = #{@qmessage.erected} == true ? 'Yes' : 'No'
        %br
        = @qmessage.erected == true ? 'Yes' : 'No'

Returned in email:
true 
@qmessage.erected 

No

So if I don't use string interpolation, I get back "@qmessage.erected". 

= #{@qmessage.erected} == true ? 'Yes' : 'No'
returns nothing

= (#{@qmessage.erected} == true) ? 'Yes' : 'No'
returns the error below.

I still think this might be a bug as why should adding parens throw an error?

Matt
Reply all
Reply to author
Forward
0 new messages