Created
March 31, 2009 03:10
-
-
Save seivan/88025 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
<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 %> |
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 | |
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