I wrote an app for shopify which works as designed. Now I wanted to add the app proxy to make the content embedded in the shop. The proxy is working fine but shopify expects a response (in my case a view) as pure liquid. The original view in ruby has some logic using several variables and objects.
I installed the liquid gem. The tutorials I walked through seem to be a little bit outdated.
@template = Liquid::Template.parse("hi {{name}}") # Parses and compiles the template
@template.render( 'name' => 'tobi' ) # Renders the output
=> "hi tobi"
This is working, but it only works with strings. I watched the railscast which I thought will be an easy way to allow liquid to access the objects. But again its outdated and the "liquid_methods" isn't working any more.
So i wrote my own method in my model:
def to_liquid
{ "title" => self.title,
"description" => self.description
}
If i try to render it with my method in my console like this:
@template = Liquid::Template.parse("Welcome to {{object.title}}")
@template.render(object.title.to_liquid)
I get the following error:
Liquid::ArgumentError (Liquid error: Expected Hash or Liquid::Context as parameter)
Now Im stuck...
What is the most simple way to access RoR Objects with liquid?