Ruby on Rails

Online Photo Gallery, Payment & Order Fulfillment: Ruby on Rails Tutorial

Friday, September 18th, 2009 | Custom Development, Improving Code, Photography, Portfolio, Programming, Projects, Ruby on Rails, Tutorials, Web Development, Websites | 4 Comments

This post is a follow-up to the post on my personal blog, titled “Ruby on Rails Photo Gallery & Shopping Cart with RESTful Authentication” In that article, I merely showed off what I’d done with Ruby on Rails, but I didn’t show anyone how. Well, I’ve gotten some comments from people asking me to show them how to build it.

That’s what this post is for.

So on to the nitty gritty details.

Start with the RESTful Authentication Tutorial:

Follow the README to install, but READ THIS FIRST to fix the ExceptionLogger error Then follow these instructions to fix the OpenID plugin error Make sure you get your recaptcha keys for the config.yml, otherwise failed login attempts will bust your application. Fill out the config & database.yml files accordingly, run your database create & migrate rakes, fire up the server and make sure it looks good. Cool? Let’s move on: Define the objects Let’s begin by pointing out what, exactly, we’ll be building this application around: Galleries of Photos that Customers can order with a private Account provided to them by an Admin who can manage the galleries and review the Orders, which are also available to their respective customers. I will go through how to set up the following models like so:

  • Galleries
    • has_many :photos
    • belongs_to :customer
    • title
    • acts_as_urlnameable (pretty URLs)
  • Photos
    • belongs_to :gallery
    • paperclip attachment: image
  • Customers
    • username, password, full name
  • Orders
    • has_many :line_items
    • belongs_to :customer
  • Line Items
    • belongs_to :order
    • quantity, size, price

So let’s build the Galleries first:

Then edit the Gallery model:

That’ll be fine for now. Let’s add the Photos model with paperclip image attached:

Now edit the Photo model as such:

You should read all about the paperclip gem if you need more info on this model. Basically, we’re telling it to allow image attachments to the Photo model. Customers can be the RESTful Authentication Tutorial User model, just need to add a couple things here:

Let’s worry about Orders and Line Items later. We’ll have to add a cart, too. I’ll cover it, but it is all derived from Agile Web Development with Ruby on Rails Third Edition

Run your rake db:migrate and confirm all is well. Delete the Galleries layout file so it uses the application layout.

Let’s go see http://localhost:3000/galleries and play around. Add a gallery and then go to edit it. This is where we’ll add SWFUpload. Follow Jim Neath’s advice for this.

You’ll want a photos controller:

The create method I use is:

I had no luck getting Jim Neath’s session fix working, so I put skip_before_filter :verify_authenticity_token in the Photos Controller. Bad? Yea, probably. I haven’t found a better way yet.

Add this code to app/views/galleries/edit.html.erb:

Which leads you to add the following partial: app/views/photos/_image.html.erb

We’ll worry about the destroy link later, let’s integrate swfupload. Download the latest copy of SWFUpload. Copy flash/swfupload.swf to public/flash (make directory first). Copy swfupload.js & upload.js (in Jim Neath’s demo app) to public/javascripts. Copy Jim Neath’s swfupload.css file to public/stylesheets. Copy Jim Neath’s images/icons folder to public/images.

Add this code to app/views/galleries/edit.html.erb:

Yep, a lot is going on there. Reload your galleries/edit page and see if it’s still working :)

Ok, so this gets you to a functioning online photo gallery. Up next will be adding user accounts, a shopping cart, ordering options, customers & paypal integration. Stay tuned!

For now, please find the source here: http://github.com/joemsak/proofs_package

And for help on your project, visit us at http://www.simplifyadvance.com

Tags: , , , ,

My First Real-World Rails Project, Part II

Thursday, November 20th, 2008 | Code, Custom Development, Programming, Projects, Ruby on Rails, Web Development, Websites | 2 Comments

Continuing my series on my first real-world rails project, I’ve made some great advancements.

Using attachment_fu, following Mike Clark’s Tutorial for Uploading / Resizing images in Ruby on Rails, and Rmagick with ImageMagick, I was able to add Categories functionality with featured images.

I also used lightbox and Coda Slider for Admin & Home presentations, respectively.

Enjoy!

http://screencast.com/t/Jli6m3lzL

Real World Rails Project, Part 1.5

Monday, November 10th, 2008 | Programming, Projects, Ruby on Rails, Web Development, Websites | 1 Comment

This is design iteration 1.5 of my first real world rails project. Read part I here.

In this iteration I added drag and droppable table rows and a pricing table for the pricing page.

Since I haven’t figured out how to update the db with the new sort orders reflected after the drag & drop action, this is not considered iteration 2.

Enjoy:

http://screencast.com/t/9bBPFCF3xp

My First Real-World Rails Project part I

Saturday, November 8th, 2008 | Programming, Projects, Ruby on Rails, Web Development, Websites | 3 Comments

I’ve decided to make a video series of my first real project in Ruby on Rails. My love of programming has been rekindled by this amazing language. It’s very true Rails was developed for the new Web. The conventions and defaults built into the framework are true genius and make any project simple, fun and agile. I can respond to any change in scope at any stage of development and give my customers a competitive advantage.

I can truly value Customer Collaboration over contract negotiation now.

Enjoy:

http://screencast.com/t/rGDhWbVru

Ruby on Rails will Save Web Development

Wednesday, November 5th, 2008 | Code, Programming, Ruby on Rails, Web Development, Work Stuff | No Comments

I’m investing time to learn Ruby on Rails and guess what? I’m becoming happier by the page.

 

Ruby on Rails is built on, emphasizes and aides developers in working according to the principles of the Agile Manifesto. I’ve never read anything more inspiring than those 12 principles. Rails has made it possible to skip functional specs, comprehensive documents and all the other garbage that stops us from delivering working software to our customers that gives them a competitive advantage.

Rails allows you to respond to change rather than try to avoid it. Face it: clients change their minds. They forget to tell you some detail until the last week of development. They decide they don’t like their original ideas and want to try something new. In order for them to remain competitive, we need to be able to adapt and respond to those changes. So if you can’t control clients and stop this from happening, why would you continue to beat the dead horse? You write pages and pages of functional specs, scope docs and project plans. But I’ve never seen a single project completed without a change to any of those. It just doesn’t happen. Rails makes it easy to work with change, rather than constantly trying to figure out how to avoid it (you can’t).

Rails makes it possible to work and grow in a dynamic and competitive world. As I learn more, I’ll post more. Until then, I suggest you try Rails and see for yourself how much better your work can be.

Search

Social Media

About the Author

I'm a Front-End Web Developer from Chicago, IL. I like XHTML, CSS, JavaScript, last.fm, 37signals, flickr, Getting Real, dogs, bikes, social life, ROWE, speaking my mind, UX/UI engineering & design, dinner dates, dancing, movies, indie rock music, hipsters, scene kids, bars, food co-ops, drums, writing, books, organic food, eco-friendly, progressive thinkers, the secret message of Jesus, and lots of other things.