I''m using Attachment fu to allow file attachments to my TimeOff model
(for an employee program). An attachment is only optional for the
app, so some TimeOffs will have files attached and some won''t.
The problem is I can''t delete a TimeOff if there is no file present.
However, it does delete fine if there is a file.
Here is my controller destroy action:
def destroy
@time_off = TimeOff.find(params[:id])
id = @time_off.employee_id
@time_off.destroy
redirect_to :action => ''list'', :id => id
end
Here is my error:
TypeError in Time offsController#destroy
can''t convert nil into String
RAILS_ROOT: script/../config/..
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/backends/
file_system_backend.rb:63:in `destroy_file''
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/callbacks.rb:333:in `send''
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/callbacks.rb:333:in `callback''
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/callbacks.rb:330:in `each''
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/callbacks.rb:330:in `callback''
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/callbacks.rb:322:in `destroy_without_transactions''
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/transactions.rb:125:in `destroy''
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/connection_adapters/abstract/database_statements.rb:
59:in `transaction''
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/transactions.rb:95:in `transaction''
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/transactions.rb:121:in `transaction''
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/transactions.rb:125:in `destroy''
app/controllers/time_offs_controller.rb:52:in `destroy''
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Chad W
2007-Nov-29 19:48 UTC
Re: Attachment_fu : Possible to delete record if no file present?
I have the same problem, and I''ve not been able to figure out a good solution yet. Anyone know? Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ebrad
2007-Dec-07 02:41 UTC
Re: Attachment_fu : Possible to delete record if no file present?
I ended up splitting attachments into their own model, which also allows multiple attachments per TimeOff, if needed. The implementation of the form is a little tricky, having to create 2 models in one form, but a tutorial on Railscasts.com helped bunches. Oh, and I added this to my Timeoff model so when I delete a TimeOff, it deletes all files too: has_many :attachments, :dependent => :destroy On Nov 29, 2:48 pm, Chad W <superw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have the same problem, and I''ve not been able to figure out a good > solution yet. Anyone know? > > Thanks!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---