0

I'm following this tutorial: http://railscasts.com/episodes/253-carrierwave-file-uploads or atleast I want to but would like to know if there are any tutorials around that explain how to give my users the ability to create pages(galleries) on the fly?

I intend to treat pages as albums. They click create album link, fill in an album title. A new page is created and from this page the user can upload photos onto the page.

kind regards

5
  • 1
    Where are you stuck??? I just saw the railscasts and its crystal clear to me. Can you be precise as to what your problem is. Commented Jan 16, 2012 at 19:00
  • I don't think he shows how to create the pages for the albums. As when I started watching the railscast they were already there. Commented Jan 16, 2012 at 19:03
  • 1
    The real fictional Gregory House wouldn't have to ask. Commented Jan 16, 2012 at 19:03
  • Yes because he is always right and knows everything but yea the tutorial doesn't show me how to create galleries and that's where I'm stuck. Commented Jan 16, 2012 at 19:07
  • You can download the source code for the railscast and then look at it. You'll find everything you need. Commented Jan 16, 2012 at 19:41

1 Answer 1

1

Albums and photos are just simple models. You can create controllers for them. Here is little example:

class Album < ActiveRecord::Base
  belongs_to :user
  has_many :album_works
  validates :title, :description, :user_id, :presence => true
  attr_accessible :title, :description
end

And for album work:

class AlbumWork <  ActiveRecord::Base
 belongs_to :album
 has_many :album_work_comments
 has_attached_file :photo,
                :styles => {
                    :preview=> "860x",
                    :slider =>  "618x246#",
                    :thumb => "315x197#",
                    :homework_main => "532x355#",
                    :homework_mini => "184x122#",
                    :big_preview => "800x600#"
                },
                :path =>  ":rails_root/public/system/album_works/:style_:id.:extension",
                :url => "/system/album_works/:style_:id.:extension",
                :default_url => "/images/photo_holder.png"

 validates_attachment_size :photo, :less_than => 2.megabytes
 validates_attachment_content_type :photo, :content_type => ['image/png', 'image/jpeg',            'image/jpg', 'image/bmp']
 attr_accessible :title, :photo
 validates :title, :album_id, :presence => true
end

Now you should create corresponding controllers and views. But they are just simple rails controllers and views. Note that I'm using paperclip, but it's only an example to show how it can be done.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, exactly what I needed. This is enough for me to continue. In my case I have a photo_gallery model and I'm going to make it have many albums, and each album will have many album comments for the photos within that album. I guess for creating these albums on the fly I can just use the build method?
Yes, you can create albums using "build" method of parent model in your case.
Thanks the exact answer I needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.