Acts as attachement

Hey guys,

I posted this a little while ago but I am still having trouble with it.

I have install acts as attachment. I am using it with one of my existing
models.
Here is the model

class Image < ActiveRecord::Base
acts_as_attachment :storage => :file_system, :max_size =>
300.kilobytes, :content_type => :image
validates_as_attachment
end

I have set up the controller to do this…

def upload_image
@image = Image.new(params[:image])
if @image.save
flash[:notice] = “Image uploaded”
redirect_to :action => “image”
else
flash[:notice] = “Image upload error”
redirect_to :action => “image”
end
end

and this is my view

%= start_form_tag :action => “upload_image”, :multipart => true %>

Upload image form my computer...
<%= file_field("image", "uploaded_data" ) %>

<%= render :partial => “license” %>

<%= submit_tag “Upload” %>

I have got the following in my database

create_table :images do |t|
  t.column :filename, :string
  t.column :size, :integer
  t.column :content_type, :string
  t.column :parent_id,  :integer
  t.column :alt, :string
  t.column :resource_id, :int
  t.column :thumbnail, :string
  t.column :width, :integer
  t.column :height, :integer
  t.column :url, :string
end

Everytime i go to upload an image i get the following error

undefined method `content_type’ for “image.jpg”:String

Any ideas would be great i am really stumped here

On Nov 27, 2006, at 4:25 PM, Stewart wrote:

%= start_form_tag :action => “upload_image”, :multipart => true %>

I just ran into this myself…

try:

start_form_tag( { :action => “upload_image” }, { :multipart => true } )

(i’m using the new 1.2 RC, so it was actually the following for me:

<% form_tag( { :action => “upload_image” }, { :multipart => true } )
do %>

)

-pete

undefined method `content_type’ for “image.jpg”:String

Make sure you have :multipart => true set correctly in the form tag.
It’s trying to call params[:uploaded_data].content_type


Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com

peter royal wrote:

try:

start_form_tag( { :action => “upload_image” }, { :multipart => true } )

(i’m using the new 1.2 RC, so it was actually the following for me:

<% form_tag( { :action => “upload_image” }, { :multipart => true } )
do %>

)

-pete

yea that was it thanks Peter and Rick!!!