xjq233p_1
xjq233p_1

Reputation: 8070

Paperclip picture is not being uploaded?

I am currently using paperclip to upload images of items to my site. I set up my paperclip exactly as https://github.com/thoughtbot/paperclip. I uploaded pictures to my site but then nothing is saved to the database. There's also images found in my public folder.

in my config,

Paperclip.options[:command_path] = "/opt/local/bin/"

In my item.rb

class Item < ActiveRecord::Base
  attr_accessible :photo_file_name, :photo_content_type, :photo_file_size,
                  :photo_updated_at
  has_attached_file :photo
end

class AddPhotoColumnToItem < ActiveRecord::Migration
  def self.up 
    add_column :items, :photo_file_name, :string
    add_column :items, :photo_content_type, :string
    add_column :items, :photo_file_size, :integer
    add_column :items, :photo_updated_at, :datetime
  end
...
end

items/_form.html.erb:

<%= form_for @item, :html => { :multipart => true } do |f| %>

  <%= f.error_messages %>
  <p>
    <%= f.file_field :photo %>
  </p>

  <p><%= f.submit %></p>
<% end %>

and finally items_controller.rb (I am using cancan)

class ItemsController < ApplicationController

  load_and_authorize_resource 

  def edit
  end

  def update
    if @item.update_attributes(params[:item])
      redirect_to @item, :notice  => "Successfully updated item."
    else
      render :action => 'edit'
    end
  end
end

I checked with firebug that an image is indeed uploaded. I even puts params and I got this:

 Parameters: {"utf8"=>"✓", authenticity_token"=>"XB0ptrmoxqRIakUB4YCBmbpYm2Pjex8KNm9g0pscpgo=", 
"item"=>{"photo"=>#<ActionDispatch::Http::UploadedFile:0x007f9c5460ef80 @original_filename="lindsay-lohan.jpg", 
@content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"item[photo]\"; filename=\"lindsay-lohan-boobs.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/var/folders/14/gbn6ww_d1fs0lrcw22w50xdr0000gn/T/RackMultipart20110909-26576-auv9vl>>}, "commit"=>"Update Item", "id"=>"1"}

Anyone know why this is not working?

Upvotes: 0

Views: 732

Answers (1)

mike zaby
mike zaby

Reputation: 488

attr_accessible i think must be just attr_accessible :photo

Upvotes: 2

Related Questions