Bolo
April 24, 2007, 12:34am
1
Hello
I would like call the validation when the user submit a file only. i
tested this
validates_as_attachment unless self.uploaded_data.blank?
NoMethodError in EnseignantsController#create
undefined method `uploaded_data’ for Enseignant:Class
But no Working`
Can you help me thanks you
Bolo
April 24, 2007, 12:48am
2
Bolo wrote:
validates_as_attachment unless self.uploaded_data.blank?
NoMethodError in EnseignantsController#create
undefined method `uploaded_data’ for Enseignant:Class
You’re getting this because “self” is a Class reference, not an instance
reference.
Try this:
validates_as_attachment :if => Proc.new {|p| not p.uploaded_data.blank?
}
(I don’t know if it’ll work, but give it a shot! :))
Bolo
April 24, 2007, 1:36pm
3
Hi
thanks you for quick answer
the error
SyntaxError in EnseignantsController#index
/Users/bmichelin/Documents/Perso/uag-histoire/site-web/app/models/
enseignant.rb:32: syntax error, unexpected kEND, expecting ‘}’
Bolo
April 25, 2007, 8:47am
4
I have to correct the syntaxe. And now i have this error
ArgumentError in EnseignantsController#index
wrong number of arguments (1 for 0)
Bolo
April 25, 2007, 2:54am
5
On 4/23/07, Antiarc [email protected] wrote:
Try this:
validates_as_attachment :if => Proc.new {|p| not p.uploaded_data.blank?
}
(I don’t know if it’ll work, but give it a shot! :))
Just peek at the source. It’s a simple method that calls 2
validations. Call them manually any custom way you want.
http://bs.techno-weenie.net/!source/2850/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb#105
–
Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
Bolo
April 25, 2007, 7:20pm
6
Thanks for you answer. I tested to custom the validation
with before_save
def before_save
unless self.filename.blank?
validates_presence_of :size, :content_type
validate :attachment_attributes_valid?
end
end
return me this error
NoMethodError in EnseignantsController#update
undefined method `validates_presence_of’ for #Enseignant:0x301e980
overrides validates_as_attachment
def validates_as_attachment
if self.filename.blank?
validates_presence_of :size, :content_type
validate :attachment_attributes_valid?
end
end
return me
NoMethodError in EnseignantsController#update
undefined method `filename’ for Enseignant:Class.
I try to find the solution my self but is not easy
Rick O. wrote:
On 4/23/07, Antiarc [email protected] wrote:
Try this:
validates_as_attachment :if => Proc.new {|p| not p.uploaded_data.blank?
}
(I don’t know if it’ll work, but give it a shot! :))
Just peek at the source. It’s a simple method that calls 2
validations. Call them manually any custom way you want.
http://bs.techno-weenie.net/!source/2850/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb#105
–
Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
Bolo
February 18, 2008, 6:24am
7
I got this to work with a combination of your methods. All of the below
code went straight into my model that used attachment_fu
validates_presence_of :size, :content_type, :if => Proc.new { |my_model|
my_model.should_i_validate? }
def before_save
if should_i_validate?
attachment_attributes_valid?
end
end
These two lines then take the place of validates_as_attachment, which
can be removed.
Not the prettiest, but then, I don’t think that there are very many
cases that justify this behavior. I figured it out so that I could have
one model that worked as an uploaded image or a templated image, but
ultimately decided to just remove this code and refactor the model so
that the attachment_fu stuff was separate from my templated image code.
Bill Harding
http://www.williambharding.com/blog
Bolo wrote:
Thanks for you answer. I tested to custom the validation
with before_save
def before_save
unless self.filename.blank?
validates_presence_of :size, :content_type
validate :attachment_attributes_valid?
end
end
return me this error
NoMethodError in EnseignantsController#update
undefined method `validates_presence_of’ for #Enseignant:0x301e980
overrides validates_as_attachment
def validates_as_attachment
if self.filename.blank?
validates_presence_of :size, :content_type
validate :attachment_attributes_valid?
end
end
return me
NoMethodError in EnseignantsController#update
undefined method `filename’ for Enseignant:Class.
I try to find the solution my self but is not easy
Rick O. wrote:
On 4/23/07, Antiarc [email protected] wrote:
Try this:
validates_as_attachment :if => Proc.new {|p| not p.uploaded_data.blank?
}
(I don’t know if it’ll work, but give it a shot! :))
Just peek at the source. It’s a simple method that calls 2
validations. Call them manually any custom way you want.
http://bs.techno-weenie.net/!source/2850/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb#105
–
Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com