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 -%>
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