diff --git a/Using-Liquid-without-Rails.textile b/Using-Liquid-without-Rails.textile index 0a08a29..f6fb4be 100644 --- a/Using-Liquid-without-Rails.textile +++ b/Using-Liquid-without-Rails.textile @@ -5,8 +5,9 @@ Let's say you have a Product class:
class Product
attr_accessor :name, :price
+
def initialize(name,price)
- @name = name
+ @name = name
@price = price
end
end
@@ -30,7 +31,7 @@ You excitedly execute your code, expecting to see your beautiful new sentence, b
undefined method `to_liquid' for #
-@to_liquid?@
+@to_liquid@ ???
Where did that come from?
Turns out you need to add a method to your class that returns your instance variables as part of a hash.
(Liquid was built to be very paranoid about not letting people access something they're not supposed to,
@@ -39,12 +40,14 @@ So, we update the @Product@ class description to include that method:
class Product
attr_accessor :name, :price
+
def initialize(name, price)
- @name = name
+ @name = name
@price = price
end
- to_liquid
- { "name" => self.name,
+
+ def to_liquid
+ { "name" => self.name,
"price" => self.price }
end
end