Forum: Ruby on Rails attachment_fu problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Acroterra (Guest)
on 2007-07-23 01:51
(Received via mailing list)
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 . 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 -%>
    <p>
      <label for="lodge_photo">Upload A Photo:</label>
      <%= file_field_tag(:uploaded_data) %>
    </p>
    <p>
      <%= submit_tag 'Create' %>
    </p>
  <% 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
Rick O. (Guest)
on 2007-07-23 03:31
(Received via mailing list)
On 7/22/07, Acroterra <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 . 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-3...
 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://weblog.techno-weenie.net
http://mephistoblog.com
This topic is locked and can not be replied to.