Skip to content

Instantly share code, notes, and snippets.

@seivan
Created March 31, 2009 03:11
Show Gist options
  • Save seivan/88026 to your computer and use it in GitHub Desktop.
Save seivan/88026 to your computer and use it in GitHub Desktop.
<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 />
<%= f.text_area :content %>
</p>
<!-- :photos is a model that has paperclip on it.
I can use :image with the photomodel and it's action, but when trying to do a nested form
everything in Post.photos is nil except the timestamp -->
<% f.fields_for @photos, :html => { :multipart => true } do |picture| %>
<%= picture.label :image %>
<%= picture.file_field :image %>
<% end %>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Back', posts_path %>
class Post < ActiveRecord::Base
require 'RedCloth'
has_many :photos
accepts_nested_attributes_for :photos, :allow_destroy => :true
class PhotoPicker < Liquid::Tag
def initialize(tag_name, photo_and_size, tokens)
super
@photo, @size = photo_and_size.split(", ")
#@size = photo_and_size[1].to_sym
end
def render(context)
context['post'][@photo.to_i].image.url(@size.to_sym)
end
end
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