Hi, rails newb here.

I'm trying to make a photo album app with rails. I'm using paperclip,
because I need to upload multiple images at the same time. But when I
upload a picture, paperclip isn't saving it. I'm not getting any errors,
it just doesn't save it. I've gone through multiple tutorials trying to
get one to work, but all of them end up with the same result. All the
functionality that I want without the pictures being uploaded :(

Album Model:

[code]
class Album < ActiveRecord::Base
  attr_accessible :name
  validates_presence_of :name
  has_many :photos, :dependent => :destroy

  accepts_nested_attributes_for :photos
end
[/code]

Photo Model:

[code]
require 'paperclip'

class Photo < ActiveRecord::Base
  belongs_to :album

  has_attached_file :data, :styles => { :medium => "300x300>", :thumb =>
"100x100>" },
                    :url =>
"/images/photos/:id/:style_:basename.:extension",
                    :path =>
":rails_root/public/images/photos/:id/:style_:basename.:extension"
  validates_attachment_content_type :data, :content_type =>
'image/jpeg', :message => "has to be in jpeg format"

end
[/code]

albums_helper

[code]
<div class="photo">
  <p>
  <% form.fields_for :photos, photo, :child_index => (photo.new_record?
? "index_to_replace_with_js" : nil) do |photo_form| %>
    <%= photo_form.file_field :data %>
    <%= link_to_function "delete", "remove_field($(this), ('.photo'))"
%><br/>
  <% end %>
  </p>
</div>
[/code]

_form.html.erb in views/ablums

[code]
<% form_for @album, :html => { :multipart => true } do |f| %>
  <%= f.error_messages %>
  <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>
  <div id="photos">
     <% if @album.new_record? %>
       <%= render :partial => 'photo', :locals => { :form => f, :photo
=> @album.photos.build } %>
    <% end %>
  </div>
  <%= add_object_link("New Photo", f, @album.photos.build, "photo",
"#photos") %>
  <p><%= f.submit "Submit" %></p>
<% end %>
[/code]

_photo.html.erb in views/albums

[code]
<div class="photo">
  <p>
  <% form.fields_for :photos, photo, :child_index => (photo.new_record?
? "index_to_replace_with_js" : nil) do |photo_form| %>
    <%= photo_form.file_field :data %>
    <%= link_to_function "delete", "remove_field($(this), ('.photo'))"
%><br/>
  <% end %>
  </p>
</div>
[/code]
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to