Last Updated: September 09, 2019
· tanema

Doing slim templates with angular & rails? Try this.

If you have a directory in your asset pipeline that you want to compile the templates and use them with your angular routes, you can do that using a setup like this.

# app/assets/javascripts/ = angular.module "website", []
app.config ($routeProvider, $locationProvider) ->
    .when "/",
      templateUrl: "<%= asset_path("welcome.html") %>"

# config/initializers/slim_assets.rb
Rails.application.assets.register_engine('.slim', Slim::Template)

# config/initializers/asset_helpers.rb
Rails.application.assets.context_class.class_eval do
  include ActionView::Helpers
  include Rails.application.routes.url_helpers

# app/assets/template/welcome.html.slim
h3 Welcome!
= image_tag asset_path("logo.png")

5 Responses
Add your response

Would be super interested to see if you could have a follow up tip for testing directives that use slim templates in rails. Nice tip btw. :D

over 1 year ago ·

I have addressed this in another post now Let me know what you think.

over 1 year ago ·

Awesome tip! One thing that tripped me up is that I had to change:

= img_tag asset_path("logo.png")


= image_tag asset_path("logo.png")
over 1 year ago ·

One more thing: I also had to rename the coffee file:



over 1 year ago ·

Ah yes those were my mistakes I have made the changes to the post. Thanks!

over 1 year ago ·