Using layouts in HAML files independently of Rails

You’re mixing up two distinct Rails feature: partials (using render) and layouts (using yield). You can add a rails-like version of either (or both) of them to a Haml only program. Partials In a rails view, you can use render :partial_name to cause the file _partial_name.html.haml to be rendered at that point in the containing … 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

Haml: Control whitespace around text

A better way to do this has been introduced via Haml’s helpers: surround = surround ‘(‘, ‘)’ do %a{:href => “https://stackoverflow.com/questions/1311428/food”} chicken Produces: (<a href=”https://stackoverflow.com/questions/1311428/food”>chicken</a>) succeed: click = succeed ‘.’ do %a{:href=>”https://stackoverflow.com/questions/1311428/thing”} here Produces: click <a href=”https://stackoverflow.com/questions/1311428/thing”>here</a>. precede: = precede ‘*’ do %span.small Not really Produces: *<span class=”small”>Not really</span> To answer the original question: I … Read more

incompatible character encodings: ASCII-8BIT and UTF-8

I solved it by following these steps: Make sure config.encoding = “utf-8” is in the application.rb file. Make sure you are using the ‘mysql2’ gem. Put # encoding: utf-8 at the top of file containing UTF-8 characters. Above the <App Name>::Application.initialize! line in the environment.rb file, add following two lines: Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = … Read more