views:

59

answers:

1

Im trying to use Liquid Template Language in my Rails Application, i've watched Ryan Bates' video over at rails cast, i pretty much follow the instructions but it just doesnt seem to work!

When I try something like

@template = Liquid::Template.parse("Hi {{name}}")
@template.render('name' => 'toby')

I get

hi toby

but when i try something like

category = Category.first
@template = Liquid::Template.parse("Hi {{category.name}}")
@template.render('category' => category)

I don't get the desired result, I get only

hi ""

Can someone please help me out with this?

+1  A: 

When the value is not a hash, you need to tell liquid which methods it can read from the passed object.

This documentation page show you how to instruct ActiveRecord. The quickest way is to use the liquid_methods macro.

Simone Carletti
The reason for this is to prevent things like `parse("Hi {{category.destroy}}")` from messing with your data.
mckeed