# Attachment\_fu problem

**URL:** <https://www.ruby-forum.com/t/attachment-fu-problem/110088>\
**Category:** Rails\
**Created:** [July 22, 2007, 11:51pm UTC](https://www.ruby-forum.com/t/attachment-fu-problem/110088 "2007-07-22T23:51:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Acroterra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@Acroterra](https://www.ruby-forum.com/u/Acroterra)\
**Post date:** [July 22, 2007, 11:51pm UTC](https://www.ruby-forum.com/t/attachment-fu-problem/110088/1 "2007-07-22T23:51:30Z")

</div>

Rails noob here,  
I am having trouble getting a simple attachment\_fu file upload form to  
work. I am using Mike C.'s tutorial on attachment\_fu -  
[http://clarkware.com/cgi/blosxom/2007/02/24](http://clarkware.com/cgi/blosxom/2007/02/24) . My code is the same as  
the tutorial but with a few minor naming conditions that are different  
and the form. I have RMagick installed and it’s dependencies as well  
as the attachment\_fu plugin. It’s not saving in the controller and I  
am getting the message “there was a problem”. I am not getting any  
Rails or Ruby errors. Can anyone help…here is my code:

## new.rhtml :

```
   <% if flash[:notice] -%>
<div id="notice"><%= flash[:notice] %></div>

```

\<% end -%\>

\<% form\_tag( {:action=\>‘create’}, :multipart=\>true ) do -%\>

Upload A Photo:  
\<%= file\_field\_tag(:uploaded\_data) %\>

  

\<%= submit\_tag ‘Create’ %\>

  
\<% end -%\>

## lodge\_photo.rhtml :

class LodgePhoto \< ActiveRecord::Base  
has\_attachment :content\_type =\> :image,  
:storage =\> :file\_system,  
:max\_size =\> 500.kilobytes,  
:resize\_to =\> ‘320x200\>’,  
:thumbnails =\> { :thumb =\> ‘100x100\>’ }

validates\_as\_attachment  
end

## lodge\_photos\_controller.rb :

class LodgePhotosController \< ApplicationController

def new  
end

def show  
@lodge\_photos = LodgePhoto.find(:all)  
end

def create

```
@lodge_photo = LodgePhoto.new(params[:lodge_photo])

if @lodge_photo.save
  flash[:notice] = 'Photo saved successfully!'
  render :action => "show"
else
  flash[:notice] = 'There was a problem!'
  render :action => "new"
end

```

end  
end

## DB Migration:

class CreateLodgePhotos \< ActiveRecord::Migration  
def self.up  
create\_table :lodge\_photos do |t|  
t.column :parent\_id, :integer  
t.column :content\_type, :string  
t.column :filename, :string  
t.column :thumbnail, :string  
t.column :size, :integer  
t.column :width, :integer  
t.column :height, :integer  
end  
end

```
def self.down
  drop_table :lodge_photos
end

```

end

---

<div class="post-metadata">

**Author:** ![Acroterra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@Acroterra](https://www.ruby-forum.com/u/Acroterra)\
**Post date:** [July 23, 2007, 1:31am UTC](https://www.ruby-forum.com/t/attachment-fu-problem/110088/2 "2007-07-23T01:31:48Z")

</div>

On 7/22/07, Acroterra [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Rails noob here,  
> I am having trouble getting a simple attachment\_fu file upload form to  
> work. I am using Mike C.'s tutorial on attachment\_fu -  
> [http://clarkware.com/cgi/blosxom/2007/02/24](http://clarkware.com/cgi/blosxom/2007/02/24) . My code is the same as  
> the tutorial but with a few minor naming conditions that are different  
> and the form. I have RMagick installed and it’s dependencies as well  
> as the attachment\_fu plugin. It’s not saving in the controller and I  
> am getting the message “there was a problem”. I am not getting any  
> Rails or Ruby errors. Can anyone help…here is my code:

When an active record model doesn’t save it means: either a  
before\_save callback returned false, or there were validation errors.  
You’re not showing any validation errors in the new.rhtml view:

\<%= error\_messages\_for :whatever %\>

Thomas Beck wrote up some issues with using this plugin on windows:  
[http://www.beckshome.com/PermaLink,guid,8fc9bb84-3f9e-4d11-aa48-fa042b4806fd.aspx](http://www.beckshome.com/PermaLink,guid,8fc9bb84-3f9e-4d11-aa48-fa042b4806fd.aspx)  
If anyone can suggest fixes, send them in as patches please. I don’t  
have a windows machine handy at the moment.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
