Everything I have seen about attachment_fu seems to deal with models which are themselves attachments. I want actual attachments. In other words, I want a user profile model to have an image attachment with size constraints... I want a photo model to have an image attachment with size contraints that are different than the user profile avatar image''s constraints... What I **DO NOT** want is a single model that is itself an attachment and which is supposed to work with every model that needs an image. How do I do this? Am I really going to have to create two separate models (UserAvatar and UploadedPhoto) just to allow Users and Photos to have an image attachment with differing constraints? -- 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 -~----------~----~----~----~------~----~------~--~---
creating 2 separate models is the best bet anyway. chances are at some point down the road not only will they need different size constraints, they will also need differing methods and other code. start off now with them separate and thank yourself in 3 months. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
OK, I''ll try it that way... but how do I handle it with a form for the user model? A separate controller for every image type is certainly overkill... Is something like this appropriate? (Obviously this isn''t written ideally, and isn''t checking for errors, etc.) # POST /user_profiles # POST /user_profiles.xml def create uploaded_data = params[:user_profile].delete(:uploaded_data) @user_profile = UserProfile.new(params[:user_profile]) unless uploaded_data.nil? if not @user_profile.avatar_image.nil? AvatarImage.delete(@user_profile.avatar_image.id) @user_profile.avatar_image = nil end new_img = AvatarImage.new(uploaded_data) new_img.save end respond_to do |format| BLAHBLAHBLAH... end 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-/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 -~----------~----~----~----~------~----~------~--~---
The way I prefer to do this is use attr_accessor to create an attribute on the user model (say, :uploaded_data), that is then checked in an after filter to create or update the associated photo model. ---- Benjamin Curtis http://catchthebest.com/ - Recruiting software http://www.bencurtis.com/ - Personal blog On Dec 27, 10:27 pm, Dave Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> OK, I''ll try it that way... but how do I handle it with a form for the > user model? A separate controller for every image type is certainly > overkill... > > Is something like this appropriate? (Obviously this isn''t written > ideally, and isn''t checking for errors, etc.) > > # POST /user_profiles > # POST /user_profiles.xml > def create > uploaded_data = params[:user_profile].delete(:uploaded_data) > @user_profile = UserProfile.new(params[:user_profile]) > > unless uploaded_data.nil? > if not @user_profile.avatar_image.nil? > AvatarImage.delete(@user_profile.avatar_image.id) > @user_profile.avatar_image = nil > end > new_img = AvatarImage.new(uploaded_data) > new_img.save > end > > respond_to do |format| > BLAHBLAHBLAH... > end > end > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Take a look at this, a small helper I wrote for exactly this task, describtion in the rdoc: http://pastie.caboo.se/132853 put it in lib/has_image.rb and then write your model class Product < ActiveRecord::Base belongs_to :image include HasImage ... end On 28 Dez., 06:36, Dave Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Everything I have seen about attachment_fu seems to deal with models > which are themselves attachments. I want actual attachments. In other > words, I want a user profile model to have an image attachment with size > constraints... I want a photo model to have an image attachment with > size contraints that are different than the user profile avatar image''s > constraints... What I **DO NOT** want is a single model that is itself > an attachment and which is supposed to work with every model that needs > an image. > > How do I do this? Am I really going to have to create two separate > models (UserAvatar and UploadedPhoto) just to allow Users and Photos to > have an image attachment with differing constraints? > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Forgot to mention, this assumes your image model is called "Image". Adjust the code accordingly if your Model is named differently On 28 Dez., 23:21, Java <jan.var...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Take a look at this, a small helper I wrote for exactly this task, > describtion in the rdoc:http://pastie.caboo.se/132853 > > put it in lib/has_image.rb and then write your model > > class Product < ActiveRecord::Base > belongs_to :image > include HasImage > ... > end > > On 28 Dez., 06:36, Dave Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > Everything I have seen about attachment_fu seems to deal with models > > which are themselves attachments. I want actual attachments. In other > > words, I want a user profile model to have an image attachment with size > > constraints... I want a photo model to have an image attachment with > > size contraints that are different than the user profile avatar image''s > > constraints... What I **DO NOT** want is a single model that is itself > > an attachment and which is supposed to work with every model that needs > > an image. > > > How do I do this? Am I really going to have to create two separate > > models (UserAvatar and UploadedPhoto) just to allow Users and Photos to > > have an image attachment with differing constraints? > > -- > > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---