Created
March 25, 2009 20:26
-
-
Save seivan/85688 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ActiveRecord::Base | |
require 'RedCloth' | |
has_many :photos | |
liquid_methods :post, :photo, :photos, :posts #Testing everything | |
#Works, but I want to be able to call it dynamicly in a textarea. | |
#SO I can use textile !{% picture 2 %}. | |
def pic(pos) | |
photos[pos.to_i].image.url(:medium) | |
end | |
#I want to pass in { photo 1 } to the render. Where 1 is an integer | |
#Look at def render. @photo is that integer. However I get an error | |
#Liquid error: undefined local variable or method `photos’ for # | |
class PhotoPicker < Liquid::Tag | |
def initialize(tag_name, photo_pos, tokens) | |
super | |
@photo = photo_pos.to_i | |
end | |
def render(context) | |
photos[@photo].image.url(:medium) | |
#rand(@photo) | |
end | |
end | |
#Works Just type {% rando 6 %} and it pulls a rand(6) | |
#Calling in View <%= textilize(Liquid::Template.parse(post.content).render) %> | |
class Rando < Liquid::Tag | |
def initialize(tag_name, photo_pos, tokens) | |
super | |
@photo = photo_pos.to_i | |
end | |
def render(context) | |
#photos[@photo].image.url(:medium) | |
rand(@photo) | |
end | |
end | |
Liquid::Template.register_tag('rando', Rando) | |
Liquid::Template.register_tag('picture', PhotoPicker) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment