Epoch's posterous

It's only a model.

Why I'm Using Rails 3 and SQL

Anyone who has followed my modest blog will be familiar with the various frameworks and databases I have tried using for singleforest.com. Well, I have finally come to a conclusion. A real conclusion this time. Since August 2010 I have been working with Rails 3 using SQLite3 as a database backend. For anyone on Hacker News that has met me in Chicago, this is the version I demoed on my iPad at the Publican.


I would like to review the frameworks and database previous iterations of singleforest.com used and why I am not using them today.

Frameworks

Rails 2
I originally started coding with rails 2. It was an easy decision to make since I had learned rails during my internship and I had continued to use it after the end of my internship. The first rails 3 beta was released early in my development process. I found rails 3 to be cleaner than earlier versions. The routing api was elegant instead of clunky. (Yes, specifying :controller and :action for every route is clunky even if you can scope them.) The addition of AREL to active record was also important once I started using sql databases, my current code base relies on it for automatic sorting and pagination.  As a result I made several attempts to use rails 3 which resulted in enormous amount of pain. During the betas several key gems such as authlogic, formtastic, and various active record gems were either not compatible or buggy. I was forced back to rails 2 until rails 3 was out of beta. Once 3 was out of beta I switched back to it.

Django
I had given Django some thought initially. I had played around with Django before and found it to be at least as large of a framework as Rails. I went with rails because of ruby. I hadn’t used python for almost a year when I started singleforest.com and I was looking at the start of a new semester in a few weeks.

Pylons
During my fights over whether to use Rails 2 or Rails 3, I decided to give a python framework a try. I dismissed Django for the same reasons as before, it’s too large of a framework to learn quickly. I figured I would be up to relearning python since I had enough free time between classes. Turns out relearning python wasn’t the problem, the documentation on pylons was. At the time I was learning pylons, the available documentation on the internet was out of date and pydoc refused to build the documentation for the version I was using. The only decent tutorial I could find was a half finished book on the previous version. I quickly ran into issues with the book. A quick trip to irc revealed to me there was no authoritative documentation, no tutorials for the current version, and no one had any idea how to actually build a pylons project from scratch. I was told to download a sample application (the pylon’s project website) and modify that. Upon doing that I found out I now had three different version of pylons on my system and all of them hated each other. I also had issues with python’s tooling. (Pydoc, virtualenv, and multiple package managers) In the end I went back to rails because I didn’t have the patience or time to deal with a pylons.

Databases

CouchDB
What’s not to love about CouchDB? From a system administrative perspective it’s the most awesome database ever. It’s crash-only, you can back it up with rsync, and it scales like nuts. From a programming perspective it’s a little more work. You need to define every query you will ever do before you do it. It’s not as bad as you think. CouchDB has a development mode that will run any query you want without an index. Slow as hell but flexible, you just have to define the indexes before you deploy. I can live with that. Data is stored as json documents in a single silo. I can live with that. For an old version of my application it would work fine. I would have loved to use it.

Why didn’t I? I need joins in the future. CouchDB could work if I was willing to make trade offs on future design. I plan to add groups to singleforest. The queries I would need can’t run on couchdb without a lot of denormalization. Adding and removing users from groups and calculating activity on groups would be expensive and require cron jobs. Ironically, groups wouldn’t be able to scale on CouchDB.

MongoDB
I liked using mongodb but the tradeoffs make me uncomfortable from a system administration perspective. MongoDB plays fast and loose with data to get high speeds as a result, it requires two servers for data safety. I don’t currently have the resources to deploy two database servers. I did not feel comfortable trying to maintain a single server against strong recommendations not to. Later I found another reason not to use MongoDB: I need joins.  

In Conclusion
Since rails 3 has matured it has been an absolute joy to work with. I do not regret having spent so much time switching between databases and frameworks. It’s given me a better appreciation for the tools I’m using now. Learning to model data in json has allowed me to model data better in sql. Fighting with python’s toolset has made me thankful for ruby version manager and bundler.

Project Update
Screenshots of the current version available on my deviantArt account.

 

Filed under  //   singleforest.com  

A look at singleforest.com: polls

I've been getting a lot of work done on singleforest.com. I've got a week left to add features before I start tracking down bugs and getting my server ready for an August 30th deployment. 

Today I finished creating polls. I wasn't going to have polls as a feature to start with but they where so easy to create I figured, why not? (Still took two days...)

This is what a poll looks like. 

Monday_bad_poll
Nothing too fancy. It works though. One design note: I wanted people to be able to see what the current votes are before they decide what to vote.

Here's what it looks like when you click vote!

Monday_that_bad_voted
The asterisk tells you what you voted on and the green bar below the main navigation tells you that your vote has been saved.

And for a bonus, you can optionally make polls that allow people to vote on multiple answers!

Multiple_votes_poll
As you can see, there are two asterisks on this one. You also get a preview of fully functioning editable comments.

Here's a bonus screen shot of that comment's edits.

Comment_history
I've been very busy. :) 

Filed under  //   screenshots   singleforest.com  

Some stuff is allowed to break on purpose.

I was playing around with markdown and I discovered attempting to submit indented text breaks things rather nicely.
This is what indented text looks like when viewed.
Breaking_indents
With a black background you have no hope of reading the submission. Editing is even worse.
Missing_editor
The text box for editing has completely disappeared... wait, there is a horizontal scrollbar!
Missing_editor_found
Ah, there it is. That's going to be a pain to edit.

I didn't plan on breaking indented text this badly but it certainly works. I don't want any user-submitted content to have indentation. I have a very specific reason for this. I want to present every submission in the same, readable format. If you want indented text, I would be happy to use css to properly indent it for you! I want the text on singleforest to be readable and consistent when submitted. Using markdown enforces some level of standardization. Restricting allowed html helps even more. (CSS may work in the preview but you ain't getting colored fonts in your literature. Yeah, I remove the <font> tag too.)

As always, comments are welcome and you can keep up to date on the mailing list on google groups. 

 

Filed under  //   singleforest.com  

Google Group created for singleforest.com

I created a google group for singleforest.com at http://groups.google.com/group/singleforest. I choose to use google groups over dokuwiki to simplify the code I would have to support. Google groups does everything I needed the wiki to do without having to modify dokuwiki to integrate with rails. It also comes with a free mailing list. 

As you can read on the group, I plan to finally deploy the site late in August. We'll see if that happens. I've got a lot of work to do. 

Filed under  //   singleforest.com  

Rails 3 RC injuries.

If you're going to run bleeding edge, you will bleed profusely. I nearly lost an arm today. I upgraded my application to Rails 3 rc from Rails 3 beta4. The list of problems I've encounter is not long but very annoying. 

  1. gem install rails --pre on top of existing rails beta causes vague untraceable errors just like upgrading to beta2 and beta3. 
    1. Solution is to remove all installed gems manually.
    2. Happily discover rvm has support for this. (rvm gemset clear)
    3. Install rails 3 rc and all dependencies. 
    4. While gems download find out in #rails-contrib that rails 3 rc isn't loading the lib/ folder
      1. Add "config.autoload_paths += %W(#{config.root}/lib)" to application.rb
    5. Ruby 1.9.1 segfautls on load. Joy of joys but not surprising.
  2. Try ruby 1.9.2-preview1
    1. Remove all installed gems
    2. Install rails 3 rc and application gems
    3. Instant sigabrt on running rails server
    4. Discover in #rails-contrib that preview1 is buggy as hell... (then why does rvm install 1.9.2 install preview1?)
  3. Try ruby 1.9.2-head
    1. No gems to remove because I need to update the head anyway.
    2. Download, compile, and install ruby 1.9.2-head
    3. Install rails 3 rc and application gems
    4. Instant internal server errors relating to failsafe failing. 
    5. #rails-contrib recommends 1.9.2-rc2
  4. Try ruby 1.9.2-rc2
    1. Not installed
    2. Download, compile, and install ruby-1.9.2-rc2
    3. Install rails 3 rc and application gems
    4. Instant internal server errors relating to failsafe failing. 
  5. Swear quietly and profusely
  6. Start testing
    1. Build new rails 3 rc application 
      1. launches okay with simple controller and view
      2. compare boot.rb, application.rb, environment/ and initializers/ with non-working app 
      3. no difference...
    2. Test difference configurations with non-working application
      1. Throw exception in home#index
      2. Works, controllers are probably okay
      3. Render index view without layout
      4. 500 Error
      5. Render index using erb instead of haml
      6. Works...
    3. Back to new rails 3 rc app
      1. Add haml gem to Gemfile and make a basic haml view
      2. Works okay. 
      3. Add haml configuration initializer from non-working application
      4. 500 Error
      5. Start playing around with different configuration options
      6. Discovered setting :encoding to :"utf-8" (notice the colon, :"" is a symbol, not a string)
      7. Using "UTF-8" (string) instead of :"utf-8" (symbol) works...
    4. Change :"utf-8" to "UTF-8" in non-working application
      1. Application works now.

I am now able to continue working on singleforest.com but I'm ready for a nap. I estimated this morning I would spend several hours just getting my application working again. For once I was correct. It only took several hours instead of the entire day. 

I would like to thank elux and nbibler in #rails-contrib on freenode for helping me out. 

Filed under  //   singleforest.com  

Old version of singleforest.com available on github

I've deployed an old copy of singleforest.com on github at http://github.com/epochwolf/singleforest-old for all you voyeurs to see. It's the same copy you see in the screen shots. 

My current version of singleforest.com is quite different. I'm not using openid anymore. I wish I could have used OpenID but the rack-openid gem has issues with ruby 1.9's encoding scheme. My current version also uses Rails 3 and MongoDB instead of Rails 2.3.5 and SQLite. 

In other news, this blog is now linked to on my public cv at careers.stackoverflow.com. I won't link you directly to it but those of you interested can now find my real name.  (I give my family about a week before one of them discovers my posts to a certain art website.) My real name would have come out anyway, I figure now is as good as a time as any to let the cat^H^H^Hwolf out of the bag.

Filed under  //   singleforest.com  

Another snag! (I gotta stop doing this)

Well, I haven't done any programming related to singleforest.com for about two weeks. I've been working pretty hard on my final project. I just finished the presentation with my group and the professor said it was good enough to pass. I should be officially graduated in a week or two. 

I've come to realize my issues with this website are not based on technology. Took 5 months to realize this. I'm pretty sure if I had someone else to look over my shoulder this website would be done by now. I never sat down and hammered out what features I needed and how some of the stuff was going to work. You can't just tack on a full notifications system. You can't be working on a website this big without some automated testing. (Yes, my bad. I never learned to use testing.)

I had exactly 10 versions of singleforest.com sitting in my project folder. Five of them are working but incomplete versions. I don't know what I'm doing. I keep trying to add extra layers to things that don't need them because I don't know where to put stuff. I'm going to take a deep breath and relax tonight.

The last SciFi Club meeting of the year is tonight. I'm going to party with all my friends that I made before I leave this school permanently. Tomorrow, I'm going to go to an all day party and enjoy myself. Only after that will I sit down and figure out what I'm going to put into singleforest.com using ruby on rails. An anemic bullet list isn't going to be good enough this time. 

Filed under  //   singleforest.com  

And the winner is:

Pylons!

I'm still figuring out if I'm going with postgres or couchdb for the backend. I need to read more on pylons before I can make that decision. (I decided on this last night but I was too busy reading to post)

Filed under  //   singleforest.com  

Singleforest.com hits a major snag

Well I've been working on singleforest.com for a while. I made the mistake of choosing the Rails 3.0 beta with Ruby 1.9 for my application. I've spent almost at much time dealing with framework and library bugs as I have with writing code. Today I hit the final bug. The openid library I've been using doesn't work with several openid providers due to the way Ruby 1.9 handles string encoding. The library throws unhandled exceptions that I can't work around. I could try patching the library myself but I'm already working with 4 patched libraries that will likely not survive the next Rails 3.0 beta release. 

So, I've decided to walk away from rails for a bit. I know I could use Rails 2.3.5 with Ruby 1.8 but I would like a change of scenery. I have previous experience with python so I have been looking at using Django or Pylons. Many people have wasted time on debating the merits of various framework for weeks before choosing one. I will have chosen a framework by this time tomorrow. 

Filed under  //   singleforest.com  

Singleforest: Registration with OpenID

Another screenshot from my development version of Singleforest.com. This is the sign up process.

Registration

And once you sign in.

Choose_your_name

Filed under  //   singleforest.com