Posts tagged as:

database

You can get cassandra at cassandra.apache.org and the ruby gem by running:

gem install cassandra

I did run into a problem with the trift_client gem when installing. If you get a Load Error, run this.

sudo chmod 644 /usr/local/lib/ruby/gems/1.8/gems/thrift_client-0.6.3/lib/thrift_client/*.rb
sudo chmod 755 /usr/local/lib/ruby/gems/1.8/gems/thrift_client-0.6.3/lib/thrift_client/connection

Here are some of the Cassandra commands from the video:

#connects to the cassandra server using the Twitter keyspace
store = Cassandra.new(“Twitter”)

# create a new column family in the Twitter keyspace called Users
cf_def = CassandraThrift::CfDef.new(:keyspace => “Twitter”, :name => “Users”)
store.add_column_family(cf_def)

# add or create a row to the column family
store.insert(“Users”, “cmaxw”, {“name” => “Charles Max Wood”, “description” => “Awesome coder”})

# remove a column from a row
store.remove(“Users”, “cmaxw”, “description”)

Download 17.2 MB
Download (iPod & iPhone) 20.9 MB
Take the 2011 Readers Survey

{ 5 comments }

Here’s a list of several of the things we discussed:

To hire Josh’s guys, go to http://pgexperts.com.

Download 6.08 MB
Download (iPod & iPhone) 4.61 MB

{ 5 comments }

I had several requests in UserVoice to provide a Many to Many tutorial in Rails. This is a demonstration of how to put together a “has and belongs to many” association and a “has many through” association.

This is somewhat basic to Ruby on Rails, but important if you need to associate different models.

Download 161.3 MB
Download iPhone & iPod 97.7 MB

{ 0 comments }

Here is what I’ve done to create this application:

  1. Use the ‘rails new’ command to create a rails application
  2. Set up the Gemfile
  3. Configure the Database
  4. Install Cucumber
  5. Install Rspec
  6. Install Devise
  7. Install CanCan
  8. Install jQuery
  9. Configure Devise

Download (HD) 84.2 MB
Download (iPod & iPhone) 47.4 MB

{ 37 comments }

Writing Code is the Easy Part is the new slogan for the website. It basically boils down to the fact that putting up syntacticly correct code is the simplest part of coding. More difficult is solving problems and all of the other things that come with having a job or working for clients.

Here are some of the things that I listed as the harder parts of coding:

  • Legacy Code
  • Readability
  • Testability
  • Best Practices
  • Writing Tests
  • Team Dynamics
  • Customer Communication
  • Translating Behavior into Code
  • Data Integrity
  • Security
  • Maintainability
  • Systems Integration
  • Server Technologies
  • Databases
  • Finding a Job
  • Hiring and Firing
  • Working on Boring stuff
  • Job Fulfillment

Here are affiliate links to some of the books that I mentioned:

Here are the links to the podcast episodes by:

Finally, I would really appreciate a $5 donation to help me get to RubyConf. Click here to lend your support to: Send Charles to RubyConf and make a donation at www.pledgie.com !

Download this Episode

{ 1 comment }

I started reading ActiveRecord::Base a few days ago and found 8 things that I didn’t know about that it offered. I also only made it about 1/4 of the way through the code. Here are a few new things I’ve learned upon further reading:

1. Find by multiple ids

Not only can you find a single record by calling find_by_id, you can find multiple records by providing an array of ids.

User.find_by_id([1, 12, 55])
# Returns 3 User objects with ids of 1, 12, and 55. If any isn't found, then RecordNotFound is raised.

2. Locking database records

If you have multiple processes that may update the same record (like incrementing a counter), then you may run into a problem where they both pull the record when the counter = 42. They each update the counter to 43 and save the record. This results in a deviation from reality of 1.

The solution is to lock the record while updating it. Here’s the code: [click to continue…]

{ 1 comment }

One problem that seems to face people when they’re attempting to move their applications into production is the best way to manage deployment of their application. This is where tools like capistrano comes in.

Capistrano was written by Jamis Buck of 37signals. In a lot of ways it has become the defacto way to deploy Ruby on Rails applications. It has also had tools like webistrano build on top of it to provide a graphical interface to the command line tool.

To get started, you need to install the capistrano gem:

gem install capistrano

[click to continue…]

{ 6 comments }

I just started building a new Rails application in version 2.3.4. One feature that I thought was particularly handy is the data seeding that is now built into Ruby on Rails.

Before this feature, you would have to do one of two things. You could seed your data in your migrations. The problem with this approach is that it clutters up your migrations, and can make for more brittle migrations. It also may or may not propagate to your test database when you run your tests, meaning that if you’re counting on it, it may not bee there.

Your second option was to create fixtures and a rake task to import the fixture data into your Rails application. The problem with this is the need to create multiple related objects across multiple files to make all of your data match up, which can create maintenance problems.

So, without further ado, here is the solution now included in Rails. You simple create a file at db/seeds.rb and place ActiveRecord create calls in the file. Here’s an example seeds.rb.
[click to continue…]

{ 8 comments }

One of the most powerful aspects of Ruby on Rails are the associations we can create between two classes. It is immensely convenient to be able to call person.posts rather than doing a SQL statement to find all of the posts with a person_id of X.

Sometimes, we have instances where the associations could be with multiple classes. For example, if we have a Page class that can be associated with an HTMLAdvertisement or an ImageAdvertisement. In that case, we really want to be able to call @page.advertisement to get the advertisement. This is where polymorphic associations come in.

Polymorphic associations allow us to associate a single attribute of the class to any number of specified classes. Here are the Page, HtmlAdvertisement, and ImageAdvertisement models:

[click to continue…]

{ 4 comments }

Rails Developers do it with Models

I saw a t-shirt at Mountain West RubyConf this year that said “Rails Developers do it with Models.” Of course, they were talking about the classes we use to access the database. In fact, in Ruby on Rails, when you think of your data, you usually think of Models, not the database. The database is more a mechanism for remembering the data when you’re not using it.

Let’s look at one of the files that were generated in Part I. This file is where the model for our blog’s posts are defined.
[click to continue…]

{ 0 comments }