The following inserts a new product, no problem. Howeve, I have to prefix the filename with "\images\" so upon retrieval it will looki in the right directory. How can I modify this code to append "\images\" to the filename column? def create @product = Product.new(@params[:product]) if @product.save flash[''notice''] = ''Product was successfully created.'' end end _________________________________________________________________ Check the weather nationwide with MSN Search: Try it now! http://search.msn.com/results.aspx?q=weather&FORM=WLMTAG --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can define a before_save callback in your model to call a function which will prepend "\images\". On Tuesday 22 August 2006 11:02, Jim Weir wrote:> The following inserts a new product, no problem. Howeve, I have to prefix > the filename with "\images\" so upon retrieval it will looki in the right > directory. > > How can I modify this code to append "\images\" to the filename column? > > def create > @product = Product.new(@params[:product]) > if @product.save > flash[''notice''] = ''Product was successfully created.'' > end > end > > _________________________________________________________________ > Check the weather nationwide with MSN Search: Try it now! > http://search.msn.com/results.aspx?q=weather&FORM=WLMTAG > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 8/22/06, Jim Weir <javawaba-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> > The following inserts a new product, no problem. Howeve, I have to prefix > the filename with "\images\" so upon retrieval it will looki in the right > directory. > > How can I modify this code to append "\images\" to the filename column? >def create @product = Product.new(@params[:product]) @product.filename = "\\images\\" + @product.filename if @product.save flash[''notice''] = ''Product was successfully created.'' end end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
This approach might be problematic if you''re creating new products in other actions or elsewhere in your rails app. Using before_save won''t pose the same problem. On Tuesday 22 August 2006 11:31, snacktime wrote:> On 8/22/06, Jim Weir <javawaba-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote: > > The following inserts a new product, no problem. Howeve, I have to > > prefix the filename with "\images\" so upon retrieval it will looki in > > the right directory. > > > > How can I modify this code to append "\images\" to the filename column? > > def create > @product = Product.new(@params[:product]) > @product.filename = "\\images\\" + @product.filename > if @product.save > flash[''notice''] = ''Product was successfully created.'' > end > end > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---