LondonGuy
LondonGuy

Reputation: 11098

How to create pages by the click of a link in ruby on rails?

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

Upvotes: 0

Views: 109

Answers (1)

Volodymyr Rudyi
Volodymyr Rudyi

Reputation: 648

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.

Upvotes: 1

Related Questions