Hello all,
Am having some serious problems with file_column plugin. I have a model, 
CaseStudy which has_one CaseStudyImage. I''m trying to validate the type
of file uploaded plus to ensure an image is uploaded, so in my 
CaseStudyImage model, I have the following -
class CaseStudyImage < Asset
  belongs_to :case_study
  validates_presence_of :filename, :message => ''can\''t be
blank''
  validates_file_format_of :filename, :in => ["gif",
"png", "jpg"],
:message => ''must be an image file''
  file_column :filename, :magick => {
    :versions => { "thumb" => "100x100",
"medium" => "220x280" }
  }
end
This works fine for creating a new case study and uploading a new image, 
however when I wish to edit the case study, I''m having some real 
problems.
My two methods for edit and update look like -
  def edit
    @case_study = CaseStudy.find(params[:id])
    @case_study_image = @case_study.case_study_image
  end
  def update
    @case_study = CaseStudy.find(params[:id])
    @image = CaseStudyImage.new(params[:case_study_image])
    unless @image.filename.nil?
      @case_study_image = @case_study.case_study_image = @image
    else
      @case_study_image = @case_study.case_study_image
    end
    @case_study_image.title = @case_study.title
    @case_study.updated_by = current_user
    if @case_study.update_attributes(params[:case_study])
      flash[:notice] = ''CaseStudy was successfully updated.''
      redirect_to :action => ''list''
    else
      render :action => ''edit''
    end
  end
On submitting a new file to replace the existing uploaded file, it 
completely ignores the validates_presence_of validation, however it 
doesn''t store the invalid file either. Checking the server trace, I can
see that the file is being deleted if it''s an invalid file.
Does anyone have any idea why this might be happening? I''ve been at
this
for almost a day trying to solve the problem with no success and  so any 
help would be really really appreciated before I tear out the little 
remaining hair I have!
Many thanks,
Alastair
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
No suggestions then? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bringing this to the top again as I''ve still not been able to resolve
my
problem! I''m really becoming unstuck with this and have had no luck
solving this issue. Can anyone suggest anything?
Cheers,
Alastair
---
Am having some serious problems with file_column plugin. I have a model,
CaseStudy which has_one CaseStudyImage. I''m trying to validate the type
of file uploaded plus to ensure an image is uploaded, so in my
CaseStudyImage model, I have the following -
class CaseStudyImage < Asset
  belongs_to :case_study
  validates_presence_of :filename, :message => ''can\''t be
blank''
  validates_file_format_of :filename, :in => ["gif",
"png", "jpg"],
:message => ''must be an image file''
  file_column :filename, :magick => {
    :versions => { "thumb" => "100x100",
"medium" => "220x280" }
  }
end
This works fine for creating a new case study and uploading a new image,
however when I wish to edit the case study, I''m having some real
problems.
My two methods for edit and update look like -
  def edit
    @case_study = CaseStudy.find(params[:id])
    @case_study_image = @case_study.case_study_image
  end
  def update
    @case_study = CaseStudy.find(params[:id])
    @image = CaseStudyImage.new(params[:case_study_image])
    unless @image.filename.nil?
      @case_study_image = @case_study.case_study_image = @image
    else
      @case_study_image = @case_study.case_study_image
    end
    @case_study_image.title = @case_study.title
    @case_study.updated_by = current_user
    if @case_study.update_attributes(params[:case_study])
      flash[:notice] = ''CaseStudy was successfully updated.''
      redirect_to :action => ''list''
    else
      render :action => ''edit''
    end
  end
On submitting a new file to replace the existing uploaded file, it
completely ignores the validates_presence_of validation, however it
doesn''t store the invalid file either. Checking the server trace, I can
see that the file is being deleted if it''s an invalid file.
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---