Hi
I'm sure this is in the wrong group - so any suggestions for a right group would be great! And you have my express permission to treat me like an idiot in replies! I have a fair amount of knowledge ... but ... obviously not enough to understand this past the basics!
I have two problems ... but only going to list one for now ...
I'm trying to use the Jim Neath code and examples with swfupload and not having much success.
I'm using Rails 2.3.5 if that's any use.
I've already had to do this in my PhotosController:
skip_before_filter :verify_authenticity_token, :only => :create
just to get the app to ignore {play nicely?) with the InvalidAuthenticityToken problems! And I promise I've read EVERY post there is on the problem from Google and beyond. I've changed more code try to solve the InvalidAuthenticityToken than I think Microsoft have ever produced ... and still no help. More on this in another post ...
But back to my problem:
I have this as part of my photo controller code:
def create if params[:Filedata] @photo = TripPhoto.new(:swfupload_file => params[:Filedata]) if @photo.save render :partial => 'photo', :object => @photo else render :text => "error" end else ... [rest omitted]
The data is being passed to the controller I think from the log ...
Processing TripPhotosController#create (for 127.0.0.1 at 2010-05-17 21:24:26) [POST] Parameters: {"Filename"=>"SYTS Logo Colour - All Red.png", "trip_id"=>"3", "action"=>"create", "authenticity_token"=>"[Omitted]", "Upload"=>"Submit Query", "controller"=>"trip_photos", "_worldtripper_session"=>"[Omitted]", "Filedata"=>#<File:/tmp/ RackMultipart20100517-44821-hoknr8-0>}
But I get the following error ...
NoMethodError (undefined method `file=' for #<TripPhoto:0x103d99410>): app/models/trip_photo.rb:13:in `swfupload_file='
I have inserted (as per Jim's instructions) the following into my TripPhoto Class...
require 'mime/types'
class TripPhoto < ActiveRecord::Base
belongs_to :trip has_attached_file :photo, :styles => { :small => "150x150>", :large => "320x240>" } validates_attachment_presence :photo validates_attachment_size :photo, :less_than => 5.megabytes
def swfupload_file=(data) data.content_type = MIME::Types.type_for(data.original_filename).first.content_type logger.warn("Data content type is: #{data.content_type}") self.file = data end
end
So I have a feeling it has something to do with the line:
self.file = data
But I really have NO IDEA what is wrong! I've spent days on this and it's not through lack of trying ...
So any help please would be fabulous!
Thanks
Darren
Oh ... BTW ...
If I make the line
@photo = TripPhoto.new(params[:Filedata])
... I end up with the following error:
NoMethodError (undefined method `stringify_keys!' for #<File:/tmp/ RackMultipart20100517-44821-hoknr8-0>): app/controllers/trip_photos_controller.rb:20:in `new'
Which makes even less sense ...