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:in
full_filename’
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:281:in
temp_paths' vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:275:in
temp_path’
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:241:in
save_attachment?' vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:344:in
set_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.