Skip to content

Instantly share code, notes, and snippets.

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
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
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
#Post.rb
def picture(pos=0)
photos[pos.to_i].image.url(:medium)
end
#Index.erb.html I NEED post.picture to get AN ARGUMENT from 'picture'
<%= textilize(Liquid::Template.parse(post.content).render('picture' => post.picture)) %>
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)
context['post'][@photo].image.url(:medium)
#rand(@photo)
<% f.fields_for :photos, :html => { :multipart => true } do |picture| %>
<%= picture.label :image %>
<%= picture.file_field :image %>
<% end %>
<h1>New post</h1>
<% @post.photos.build if @post.photos.empty? %>
<% form_for(@post) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<h1>New post</h1>
<% form_for(@post) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :content %><br />
<h1>New post</h1>
<% form_for(@post) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :content %><br />
We couldn’t find that file to show.