I'm trying to work with slim-lang for my web project. I have the following setup:

  • ruby 2.0
  • rails 4.0
  • node v0.10.17

This setup is working with grunt and the grunt-slim plugin.

At first glance, the slim templates compile all right, but when I try to work with partials, I get an error:

NoMethodError: undefined method `render' for #Object:0x000000029db190

Example code to reproduce:

_foo.slim:

a (href="#") click

bar.slim:

= render 'foo'

I'm a front end developer, so I don't know enough about ruby or rails. I don't understand what causes this error-- is it the grunt-slim plugin or something to do with ruby?

Any help will be appreciated!

有帮助吗?

解决方案

So the grunt-slim plugin calls the command-line slim utility. I was able to reproduce the error message you're getting by creating the two example files you gave and running:

slimrb --trace bar.slim

This error is happening because a bare render method isn't part of the slim gem, it's part of rails. I was able to get the above command to work by changing bar.slim to be:

= Slim::Template.new('_foo.slim').render

This is clearly more verbose, sorry. I'm not sure if there's a better way to integrate grunt and rails' templates that would get around this issue, but you could just let rails do the rendering.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top