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 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bolo wrote:> validates_as_attachment unless self.uploaded_data.blank? > > NoMethodError in EnseignantsController#create > > undefined method `uploaded_data'' for Enseignant:ClassYou''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! :)) -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
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 ''}'' On 23 avr, 18:48, Antiarc <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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! :)) > > -- > Posted viahttp://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?hl=en -~----------~----~----~----~------~----~------~--~---
On 4/23/07, Antiarc <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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! :))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 Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.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?hl=en -~----------~----~----~----~------~----~------~--~---
I have to correct the syntaxe. And now i have this error ArgumentError in EnseignantsController#index wrong number of arguments (1 for 0) On 24 avr, 07:16, Bolo <mala...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 ''}'' > > On 23 avr, 18:48, Antiarc <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > 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! :)) > > > -- > > Posted viahttp://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?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for you answer. I tested to custom the validation
1. 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>
2. 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 Olson wrote:> On 4/23/07, Antiarc
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 Olson
> http://lighthouseapp.com
> http://weblog.techno-weenie.net
> http://mephistoblog.com
--
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?hl=en
-~----------~----~----~----~------~----~------~--~---
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
>
> 1. 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>
>
> 2. 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 Olson wrote:
>> On 4/23/07, Antiarc
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 Olson
>> http://lighthouseapp.com
>> http://weblog.techno-weenie.net
>> http://mephistoblog.com
--
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?hl=en
-~----------~----~----~----~------~----~------~--~---