Attachment_fu problems on updates

On the creation of a member the member’s picture uploads as it should.
However, when updating the member, while selecting a new picture, an
error is thrown:

can’t convert nil into String
RAILS_ROOT: /Users/chris/Documents/Projects/Rails/CommunityCMS/trunk

Application Trace | Framework Trace | Full Trace
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb:21:in
join' vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb:21:infull_filename’
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:281:in
temp_paths' vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:275:intemp_path’
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:241:in
save_attachment?' vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:344:inset_size_from_temp_path’
vendor/rails/activerecord/lib/active_record/callbacks.rb:307:in `send’

If I update the user without selecting a new picture, the users picture
is lost (the db row values are set to nil)

Here is the controller code for the update:

def update
@member = Member.find(params[:id])
#try to not set the photo if a new one is not uploaded
@photo = @member.build_photo(params[:photo]) unless
params[:photo].nil?

respond_to do |format|
  if @member.update_attributes(params[:member])
      ....
end

end

Here is the Member model code:

class Member < ActiveRecord::Base
validates_presence_of :first_name, :last_name, :city, :region,
:region_code
has_many :groups, :through => :group_members
has_one :photo, :as => “photo_for”

validates_associated :photo

end

Here is the file_system_backend (where the error is occurring):

def full_filename(thumbnail = nil)
file_system_path = (thumbnail ? thumbnail_class :
self).attachment_options[:path_prefix].to_s
#here is the join that is failing
#logger.info “rails root:” + RAILS_ROOT => /Users/…
#logger.info “file sys path” + file_system_path => public/photos
#logger.info thumbnail => nothing show up here
File.join(RAILS_ROOT, file_system_path,
*partitioned_path(thumbnail_name_for(thumbnail)))
end

The photo model is polymorphic which is why it exists as a separate
model.

I have never had this problem before, but this is the first polymorphic
relation that I have used to link to the uploaded images.

Thanks for the help.

Some of the issues above have been fixed, but I am still having problems
uploading a photo when editing a member that was created without a
photo.

It is failing in the exact same spot.

Thanks for the help.

=============================
TypeError in Admin/membersController#update

can’t convert nil into String
RAILS_ROOT: /Users/chris/Documents/Projects/Rails/CommunityCMS/trunk

Application Trace | Framework Trace | Full Trace
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb:21:in
join' vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb:21:infull_filename’
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:281:in
temp_paths' vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:275:intemp_path’
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:241:in
save_attachment?' vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:344:inset_size_from_temp_path’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:307:in
send' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:307:incallback’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:304:in
each' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:304:incallback’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:269:in
valid?' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/validations.rb:933:insave_without_transactions’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:108:in
save' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:66:intransaction’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:80:in
transaction' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:100:intransaction’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:108:in
save' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:120:inrollback_active_record_state!’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:108:in
save' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/has_one_association.rb:30:inreplace’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/has_one_association.rb:86:in
new_record' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/has_one_association.rb:18:inbuild’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations.rb:1114:in
send' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations.rb:1114:inbuild_photo’
app/controllers/admin/members_controller.rb:75:in `update’

Hello, i having troubles when try replace existing file for new, get
the same error… some one can help?

On 31 dez 2007, 03:24, Chris O. [email protected]

Thanks Chris, i post my question and code in another post in this
link,
http://groups.google.de/group/rubyonrails-talk/browse_thread/thread/f2510dfd535ebaf0

On 22 jan, 22:46, Chris O. [email protected]

Daniel L. wrote:

Hello, i having troubles when try replace existing file for new, get
the same error… some one can help?

On 31 dez 2007, 03:24, Chris O. [email protected]

The problem for me was that I was missing the unless params[:photo].nil?
condition in the create method, which messed up the data when trying to
do the update.

If that doesn’t help you out at all, post some of your code so we can
take a look at it.