768x90 Getting Online Shouldn't be Tough- $7.49 .com Domains at Go Daddy

Create Photo Gallery less than 10 MINUTES

There's many ways to create photo gallery, i want share my experience with very instant photo gallery. Begginer or advance can do it, it's easy. I am using windows OS, Ruby ruby 1.8.5. Let's Start your ruby

  • Step 1 : Download Rmagick(2.3.0) & imageMagick(6.4.0) in 1 Package Here (Download Package).
if you use linux, install imageMagick Library (sudo apt-get install libmagick9-dev) and then install rmagick (sudo gem install rmagick), after that skip step 2.
  • Step 2 : extract package to /ruby/your_app/tmp, make sure that rmagick-2.x.x.tar.gz and rmagick-2.x.x-x86-mswin32.gem are in that tmp folder. After that run it:
gem install rmagick --local
.
  • Step 3 : Install attachment_fu plugin
ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/
  • Step 4 : Generating the Scaffolding Code
ruby script/generate scaffold_resource Gallery
.
  • Step 5 : Create Gallery Table for DataBase or Gallery Migration, open your db/migrate/001_create_galleries.rb, then insert it :
class CreateGalleries < Migration
t.column :filename, :string, :limit => 255
t.column :path, :string, :limit => 255
t.column :parent_id, :integer
t.column :thumbnail, :string, :limit => 255
t.column :size, :integer
t.column :width, :integer
t.column :height, :integer
end
end

def self.down
drop_table :galleries
end
end
  • Step 6 : After that run this command : rake db:migrate
  • Step 7 : Set up your picture size, open app/models/gallery.rb
class Gallery < ActiveRecord

has_attachment :storage => :file_system,
:resize_to => '>550x>413',
:thumbnails => { :thumb => '>100x>75'},
:size => 0.megabyte..3.megabytes,
:content_type => :image,
:processor => 'Rmagick'
validates_as_attachment


end

  • Step 8 :Edit your controller gallery_controller.rb
def index

@gallery_pages = Paginator.new(self, Gallery.find(:all).count, 5, params[:page])
@photos = Gallery.find(:all, :order => 'created_at DESC', :limit => @gallery_pages.items_per_page, :offset => @gallery_pages.current.offset)

respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @gallery.to_xml }
end
end


def create

@gallery = Gallery.new(params[:gallery])
@galleries = Gallery.find(:all)

respond_to do |format|

if @galleries << @gallery flash[:notice] = 'Gallery was successfully created.' format.html { redirect_to(@gallery) } format.xml { render :xml => @gallery, :status => :created, :location => @gallery }
else
format.html { render :action => "new" }
format.xml { render :xml => @gallery.errors, :status => :unprocessable_entity }
end
end
end
  • Step 9 :Edit your uploading form to your new.rhtml
<%= error_messages_for :photo %>
<% form_for(@gallery,
:html => { :multipart => true }) do |f| %>

select a photo to upload

title:
<%= f.text_field 'title' %>

Description:
<%= f.text_area 'body', :rows => 6, :cols => 40 %>

Photo:
<%= f.file_field 'uploaded_data' %>

<%= submit_tag 'Upload Photo' %> or <%= link_to 'Cancel', galleries_path %>
<% end %>

  • Step 10 : Activate your server and run your application.

If you got error or problem please give me feedback. Enjoy and good luck.


.

No Response to "Create Photo Gallery less than 10 MINUTES"

 
powered by Blogger