Topic: HOWTO: Get started with attachment_fu

Photo Gallery with Attachment_Fu

Photo galleries can be developed easily with Rails using the attachment_fu plugin. In this post i will give an example of how you could get started with this plugin, based on my own experience with it. Please let me know if you come up with any errors, i have this working in a couple of demo apps that are on Rails 2.0.2, but may not have copied the code over perfectly.

http://svn.techno-weenie.net/projects/p … chment_fu/

To use attachment_fu, you need to also choose an Image Processor, eg:

Rmagick
http://rmagick.rubyforge.org/

minimagick
http://rubyforge.org/projects/mini-magick/

image_science
http://seattlerb.rubyforge.org/ImageScience.html

I will be using Rmagick with ImageMagick (you need both).

"RMagick is an interface between the Ruby programming language and the ImageMagick and GraphicsMagick image processing libraries."

"ImageMagick is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and B

Re: HOWTO: Get started with attachment_fu

If Photo belongs to User, should there not be a user_id field in the photo table? Or is there some magic way in which parent_id is automatically identified with user_id?

Re: HOWTO: Get started with attachment_fu

Hi nanijoe

Yes, there is a user_id field in the photo table! Refer to the migration code smile

PJ.

Re: HOWTO: Get started with attachment_fu

How would I go about adjusting this say if I was using a diffrent model than user such as Property and Property has_many :photos ? Any suggestions?

Re: HOWTO: Get started with attachment_fu

the main thing I am not sure of is what to replace current_user with? params[:property_id] possibly?

Last edited by st23am (2008-02-20 13:34:03)

Re: HOWTO: Get started with attachment_fu

Got it figured out. Please disregard the above. Awesome tutorial thank you!

Re: HOWTO: Get started with attachment_fu

Cool, thanks smile

PJ.

Re: HOWTO: Get started with attachment_fu

Hello,

I am newbie to ror, would you give a favor pls. I

Re: HOWTO: Get started with attachment_fu

Hi, and thanks in advance for your help.

I am trying to use this in a Rails 1.2 app, and I believe there is an issue with routing.(?)  I am NOT in Rials 2 YET, as I am just getting the hang of this, and all my reference books are pre 2.0, then BAM! a completely new version. 

So, I will switch to 2 when this app is done ( and hopefully there are more Rails 2 books available).

Meanwhile, I installed the plugin to upload PDF files ( No Rmagic, or minimagic, or image_science installed, since I am NOT processing any images(YET), just uploading straight PDF files to be displayed in a list, and downloadable when clicked) and am encountering the following errors:

The model is 'instruction', the controller is 'instrtuctions'

Here is model/instruction.rb:

class Instruction < ActiveRecord::Base
has_attachment :content_type => 'application/pdf'
has_attachment :storage => :file_system
has_attachment :max_size => 3.megabytes
validates_as_attachment
end

Here is the form instructions/new.rhtml
<h1>New instruction</h1>
<% form_for(:instruction, :url => { :action => "create" },
                      :html => { :multipart => true }) do |f| -%>
  <p>
    <label for="instruction">Upload instruction PDF:</label>
    <%= f.file_field :uploaded_data %>
  </p>
  <p>
    <label for="instruction">Filename:</label>
    <%= f.text_field :filename %>
  </p>
  <p>
    <%= submit_tag 'Create' %>
  </p>
<% end %>
<%= link_to 'Back', :action => 'list' %>

Here is my instructions migration:
class CreateInstructions < ActiveRecord::Migration
  def self.up
    create_table :instructions do |t|
      ### for dowloading images, as attachment_fu     
            t.column :size,         :integer 
            t.column :content_type, :string   
            t.column :filename,     :string   
            t.column :height,       :integer  # unused for now
            t.column :width,        :integer  # unused for now
      ### that reference images that will be thumbnailed:
            t.column :parent_id,    :integer  # unused for now
            t.column :thumbnail,    :string   # unused for now
            t.column :db_file_id,   :integer  # unused for now
      ### for 'instructions' in general     
            t.column :name,     :string   # name of the instructions
            t.column :category, :string   # american, european, press, etc.
            t.column :link, :string       # link to display page, for later use
    end
  end

  def self.down
    drop_table :instructions
  end
end


Here is the error I get when clicking 'submit' on a new upload:
undefined local variable or method `full_filename' for

and here is the error I get when trying to display the instructions/list.rhtml page:

 Showing app/views/instructions/list.rhtml where line #3 raised:

undefined method `public_filename' for #<Instruction:0x26c9434>

Extracted source (around line #3):

1: <h1>Most Wanted</h1>
2: <% for instruction in @instructions -%>
3:   <%= link_to image_tag(instruction.public_filename), instruction.public_filename %>
4: <% end -%>
5:
6:


Again, your help is greatly appreciated, and yes I will be moving to Rails 2 AFTER this project is complete.  I am under a deadline that will surely be missed if I try to switch mid stream, since I am relatively new to rails.

Darin

Last edited by darinmurray (2008-02-22 12:09:54)

Re: HOWTO: Get started with attachment_fu

musabd,

I am not familiar with ruby extranet command...

Maybe just try:

ruby script/plugin install http://svn.techno-weenie.net/projects/p … chment_fu/

darinmurray,

What's in your controller? Attachment_fu automatically stores the filename, so maybe you can leave that field out in your form?

PJ.

Re: HOWTO: Get started with attachment_fu

pjay79, thanks for your response. I tried leaving the filename out of the form, this is the error I get on clicking submit: (selecting a small 300k readme.pdf from local desktop)

 NoMethodError in InstructionsController#create

undefined method `data=' for #<DbFile:0x266f024 @attributes={}, @new_record=true>

RAILS_ROOT: script/../config/..
Application Trace | Framework Trace | Full Trace

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1857:in `method_missing'
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb:30:in `save_to_storage'
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:374:in `after_process_attachment'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `send'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `callback'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `each'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `callback'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:243:in `create_or_update'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1545:in `save_without_validation'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:752:in `save_without_transactions'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save'
app/controllers/instructions_controller.rb:25:in `create'

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1857:in `method_missing'
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb:30:in `save_to_storage'
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:374:in `after_process_attachment'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `send'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `callback'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `each'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `callback'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:243:in `create_or_update'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1545:in `save_without_validation'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:752:in `save_without_transactions'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `send'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `perform_action_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in `call_filter'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:638:in `call_filter'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:438:in `call'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:637:in `call_filter'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in `perform_action'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `send'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `process_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in `process_without_session_management_support'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in `process'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in `process'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in `dispatch'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `synchronize'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in `process_client'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `process_client'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `initialize'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `initialize'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `new'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in `run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `each'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in `run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:60
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
script/server:3

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1857:in `method_missing'
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb:30:in `save_to_storage'
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:374:in `after_process_attachment'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `send'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `callback'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `each'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `callback'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:243:in `create_or_update'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1545:in `save_without_validation'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:752:in `save_without_transactions'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save'
app/controllers/instructions_controller.rb:25:in `create'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `send'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `perform_action_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in `call_filter'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:638:in `call_filter'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:438:in `call'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:637:in `call_filter'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in `perform_action'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `send'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `process_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in `process_without_session_management_support'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in `process'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in `process'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in `dispatch'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `synchronize'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in `process_client'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `process_client'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `initialize'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `initialize'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `new'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in `run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `each'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in `run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:60
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
script/server:3

Request

Parameters: {"commit"=>"Create", "instruction"=>{"uploaded_data"=>#<File:/var/folders/4p/4ppVlqgcHYOipxlB6VOUik+++TI/-Tmp-/CGI1380-0>}}

Show session dump


Here is my controller
class InstructionsController < ApplicationController
  def index
    list
    render :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
    @instruction_pages, @instructions = paginate :instructions, :per_page => 10
  end

  def show
    @instruction = Instruction.find(params[:id])
  end

  def new
    @instruction = Instruction.new
  end

  def create
    @instruction = Instruction.new(params[:instruction])
    if @instruction.save
      flash[:notice] = 'Instruction was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

  def edit
    @instruction = Instruction.find(params[:id])
  end

  def update
    @instruction = Instruction.find(params[:id])
    if @instruction.update_attributes(params[:instruction])
      flash[:notice] = 'Instruction was successfully updated.'
      redirect_to :action => 'show', :id => @instruction
    else
      render :action => 'edit'
    end
  end

  def destroy
    Instruction.find(params[:id]).destroy
    redirect_to :action => 'list'
  end
end


Thanks again for your input.  I thought perhaps I should install ImageMagick, even though I am not doing any image processing (but will add that soon), but no luck yet, that is not an easy task.  Still sorting through the differences in tutorials on how to actually do it. ( mac osx 10.5 on intel g5 X11 installed)

Darin

Re: HOWTO: Get started with attachment_fu

I have a controller by which user can signup or edit profile. There they can upload their photo, which should be optional.


Here is my view code
===============================

  <% form_for(@user, :html => { :multipart => true }, :url => { :action => "update" })  do |form| %>


          <p>
            <b>Email:</b><br />
            <%= form.text_field :email, :size=>38 %>
          </p>

          <p>
                <b>Photo</b><br />
                <%= form.file_field :uploaded_data %>
          </p>

           <p>
            <%= form.submit "Save Changes", { :class=>"more"} %>
          </p>
  <% end %>



Here is the model code:
=======================================

class User < ActiveRecord::Base
  validates_presence_of :email
  has_attachment :content_type => :image,
                 :storage => :file_system,
                 :max_size => 500.kilobytes,
                 :resize_to => '320x200>',
                 :thumbnails => { :thumb => '100x100>'},
                 :processor => :MiniMagick
  #validates_as_attachment               
end

Here is the controller code to update:
========================================
  def update
    @user = User.find(params[:id])   

    respond_to do |format|
      if @user.update_attributes(params[:user])
        flash[:notice] = 'User was successfully updated.'
        format.html { redirect_to(@user) }       
        format.xml  { head :ok }
      end
    end
  end
========================================================================

When user update their profile without, it is thrown an error message:

can't convert nil into String


uploading photo/file is optional to my controller.

how can i solve this.

Musa

Re: HOWTO: Get started with attachment_fu

Just a quick refactor
New routing in 2.0

map.resources :users, :has_many => :photos

instead of
map.resources :users do |user|
  user.resources :photos
end

Re: HOWTO: Get started with attachment_fu

public_filename function not recognized, I'm using option :storage => :db_file and saving images as blobs in the db_files table. Does the public_filename function work with this settings? How can I display the images?