Jon
2012-Sep-03 21:53 UTC
Newbie question: How do I get CarrierWave to save my files in a has_many / belongs_to setup?
I posted this on StackOverflow, and didn''t get much love. I''m hoping someone here can help me. Thanks in advance! I have a form that displays information about a single commercial real estate property. I am trying to create a feature on it that allows the user to upload files to Amazon S3 that will then be associated with that property. In a separate question, I asked how this relationship should work. I have a series of questions about this whole thing, but it seems that Stack Overflow likes to keep each question limited to a specific topic. I''ve created a relationship so that Properties has_many Uploadedfiles and Uploadedfiles belongs_to Properties. I added a column to the Uploadedfile table called "uploaded_file" and mounted CarrierWave to that column I''ve read through the Readme and Wiki for Carrierwave and Carrierwave_direct. They both talk about adding a single Avatar to a new User, when that new User is created. In my case, the property is already created, and I want to be able to upload multiple files (one at a time, for now) to that Property. (later, I will add a feature that lists out links to each of the uploaded files so that the user can download and open them). Here is what the readme says. What do I need to do in my controllers and views to make this work for me? Rails If you are using Rails and you''ve mounted your uploader like this: class User < ActiveRecord::Base mount_uploader :avatar, AvatarUploader end things just got a whole lot easier. You can generate a direct upload form like this: class AvatarController < ApplicationController def new @uploader = User.new.avatar @uploader.success_action_redirect = new_user_url end end <%= direct_upload_form_for @uploader do |f| %> <%= f.file_field :avatar %> <%= f.submit %> <% 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/jj-DucRPNP8J. For more options, visit https://groups.google.com/groups/opt_out.
Tad Preston
2013-Jan-31 13:14 UTC
Re: Newbie question: How do I get CarrierWave to save my files in a has_many / belongs_to setup?
Hi Jon, I have a similar situation. Do you have a solution yet? I already have a user created and want to only add a profile image. It seems that the success_action_redirect performs a get but I would like to actually perform a post to create a record for that image. Tad On Monday, September 3, 2012 4:53:44 PM UTC-5, Jon wrote:> > I posted this on StackOverflow, and didn''t get much love. I''m hoping > someone here can help me. Thanks in advance! > > I have a form that displays information about a single commercial real > estate property. I am trying to create a feature on it that allows the user > to upload files to Amazon S3 that will then be associated with that > property. In a separate question, I asked how this relationship should > work. I have a series of questions about this whole thing, but it seems > that Stack Overflow likes to keep each question limited to a specific > topic. > > I''ve created a relationship so that Properties has_many Uploadedfiles and > Uploadedfiles belongs_to Properties. I added a column to the Uploadedfile > table called "uploaded_file" and mounted CarrierWave to that column > > I''ve read through the Readme and Wiki for Carrierwave and > Carrierwave_direct. They both talk about adding a single Avatar to a new > User, when that new User is created. In my case, the property is already > created, and I want to be able to upload multiple files (one at a time, for > now) to that Property. (later, I will add a feature that lists out links to > each of the uploaded files so that the user can download and open them). > > Here is what the readme says. What do I need to do in my controllers and > views to make this work for me? > > Rails > > If you are using Rails and you''ve mounted your uploader like this: > > class User < ActiveRecord::Base > mount_uploader :avatar, AvatarUploader end > > things just got a whole lot easier. You can generate a direct upload form > like this: > > class AvatarController < ApplicationController > def new > @uploader = User.new.avatar > @uploader.success_action_redirect = new_user_url > end end > <%= direct_upload_form_for @uploader do |f| %> > <%= f.file_field :avatar %> > <%= f.submit %> <% end %> > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Pud7U2dZJCEJ. For more options, visit https://groups.google.com/groups/opt_out.
tamouse mailing lists
2013-Feb-02 03:37 UTC
Re: Re: Newbie question: How do I get CarrierWave to save my files in a has_many / belongs_to setup?
Did you ask on the Carrierwave mailing list/google group? http://groups.google.com/group/carrierwave -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.