bingo bob
2010-Mar-17 17:29 UTC
Associating a default paperclip image from a different model
Here''s some code, this is my NewsItem model as you can see...
class NewsItem < ActiveRecord::Base
belongs_to :country
has_attached_file :image, :styles => { :original =>
''57x57'' },
:default_url => ''/images/football.png''
# has_attached_file :image,
# :styles => { :original =>
''57x57'' },
# :default_url => self.country.flag.url
validates_attachment_content_type :image, :content_type =>
[''image/png''], :message => "only pngs are
allowed."
validates_presence_of :title
validates_length_of :title, :within => 3..50
validates_presence_of :url
end
I have a Country model also which has a flag (paperclip attached
image)...What I''d like to do is make the default image for the NewsItem
be the Country flag? My commented out code shows my unsuccessful
attempt, I believe it''s along those lines, but not what I have!
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Mar-17 17:37 UTC
Re: Associating a default paperclip image from a different model
On 17 March 2010 17:29, bingo bob <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Here''s some code, this is my NewsItem model as you can see... > > class NewsItem < ActiveRecord::Base > belongs_to :country > has_attached_file :image, :styles => { :original => ''57x57'' }, > :default_url => ''/images/football.png'' > > # has_attached_file :image, > # :styles => { :original => ''57x57'' }, > # :default_url => self.country.flag.url > > validates_attachment_content_type :image, :content_type => > [''image/png''], :message => "only pngs are allowed." > validates_presence_of :title > validates_length_of :title, :within => 3..50 > validates_presence_of :url > end > > I have a Country model also which has a flag (paperclip attached > image)...What I''d like to do is make the default image for the NewsItem > be the Country flag? My commented out code shows my unsuccessful > attempt, I believe it''s along those lines, but not what I have!What was the result of your code? Was it a syntax error or run time? Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Mar-20 14:19 UTC
Re: Associating a default paperclip image from a different
Hi Colin, Here''s the error I get with my code... undefined method `country'' for #<Class:0x10344bac0> just to reiterate here, what i''d like to do here is set the default image (paperclipped) to be that of the "belonged_to" country... bb. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Mar-20 14:19 UTC
Re: Associating a default paperclip image from a different
Just to be clear that error is generated with this code in place...
class NewsItem < ActiveRecord::Base
belongs_to :country
# has_attached_file :image, :styles => { :original =>
''57x57'' },
:default_url => ''/images/football.png''
has_attached_file :image,
:styles => { :original => ''57x57''
},
:default_url => self.country.flag.url
validates_attachment_content_type :image, :content_type =>
[''image/png''], :message => "only pngs are
allowed."
validates_presence_of :title
validates_length_of :title, :within => 3..50
validates_presence_of :url
end
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.