ruby inside javascript block [slim template]

You can use a style similar to string interpolation. See example below. javascript: var config = { custom: “#{my_value ? ‘truthy’ : ‘falsy’}”, current_user: #{raw current_user.to_json} }; ** Update below ** If you want more advanced configuration I would recommend to create a class, for example class ClientConfig attr_accessor :foo, :bar # .. code def … Read more

How to access instance variables in CoffeeScript engine inside a Slim template

What’s happening is that “#{@user_name}” is being interpreted as CoffeeScript, not as Ruby code that’s evaluated and injected into the CoffeeScript source. You’re asking, “How do I inject a Ruby variable into my CoffeeScript source?” The short answer is: Don’t do this. The Rails team made an intentional decision not to support embedded CoffeeScript in … Read more

Best way to handle data attributes in Slim

There are multiple ways in Slim As Hash Attributes which will be hyphenated if a Hash is given (e.g. data={a:1,b:2} will render as data-a=”1″ data-b=”2″) Use it directly as “mu is too short” mentioned, quite intuitive. a data-title=”help” data-content=”foo” Use Ruby code. I often do this and rarely above. = link_to ‘foo’, bar_path, data: {a: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)