I'm using jquery-mobile with Ruby On Rails.
I want to create a button link which implies to have data-role="button"
appear in the generated HTML.
I've tried:
<%= link_to "Play", game_play_path, :data-role => "button" %>
But then, I get an error
undefined local variable or method `role' for #<#<Class:0x007fdc25668ee8>:0x007fdc25658610>
Is there a way to escape the dash using the :xxx
notation or should I just use the "xxx"
notation?
(I agree it's a cosmetic question, but I want my code to be consistent and don't like exceptions)
"\n" is newline, '\n\ is literally backslash and n.
Ruby symbols are defined as “scalar value objects used as identifiers, mapping immutable strings to fixed internal values.” Essentially what this means is that symbols are immutable strings. In programming, an immutable object is something that cannot be changed.
Ruby symbols are created by placing a colon (:) before a word. You can think of it as an immutable string. A symbol is an instance of Symbol class, and for any given name of symbol there is only one Symbol object.
Use single quotes around the symbol name, with the colon prefix:
:'data-role' => 'button'
And here is a nice reference on symbols:
http://www.troubleshooters.com/codecorn/ruby/symbols.htm#_What_do_symbols_look_like
After Ruby 1.9
you can also do
'data-role': 'button'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With