From the category archives:

Screencasts

My Equipment:

Podcasting Club Setup:

Play

{ 4 comments }

When preparing to add some layout features to JotRod, I realized it was a Rails 3.0.9 application. Here’s a quick rundown on upgrading to Rails 3.1.3.

Download 164.7 MB
Download (iPod & iPhone) 37.9 MB
Take the 2011 Readers Survey

{ 5 comments }

In order to get someone a timeline in JotRod, we need followers and following lists to compile the Jots from. This means that we need to add a new ColumnFamily called Followers and another one called Following. We don’t have the joins capability from relational databases to do this for us.

I’m going to hijack the User model’s database connection to create the ColumnFamilies. (We don’t have migrations, yet.) Here’s what I ran in the rails console:

cf_def = CassandraThrift::CfDef.new(:keyspace => "JotRod", :name => "Followers")
User.connection.add_column_family(cf_def)
cf_def = CassandraThrift::CfDef.new(:keyspace => "JotRod", :name => "Following")
User.connection.add_column_family(cf_def)

Now that we have the ColumnFamilies, I want to have syntax like this to define the relationships on the User model:

list :followers, :User
list :following, :User

This should provide the following API:

#followers – returns an array of users as specified from the Followers ColumnFamily
#followers<<(user)  – adds the user to the User object’s followers list if it’s not already there

and a similar API for following.

Sandra’s repository

JotRod’s repository

Download 680 MB
Download (iPod & iPhone) 165 MB
Take the 2011 Readers Survey

{ 2 comments }

In the Jots (like tweets) in JotRod, I needed to generate a hash on creation as the key for the Jots. So, I determined that the easiest way to do that was to include ActiveModel Callbacks.

The module is pretty simple to add to your classes. Here’s a demo of how to add it to Sandra.

Sandra’s repository

JotRod’s repository

Download 223 MB
Download (iPod & iPhone) 37 MB
Take the 2011 Readers Survey

{ 0 comments }

Here’s an introduction to creating a Rails connector gem for an ORM with a model generator.

Download 352.3 MB
Download (iPod & iPhone) 84.7 MB
Take the 2011 Readers Survey

{ 1 comment }

When I started playing with Cassandra, I wound up writing part of an ORM to get what I needed from it.

I want to build actual projects with Rails, Ruby, or other technologies for my videos rather than just narrowly demonstrate a piece of technology. So, I’m bringing you up to speed with Sandra so that as I continue with the Twitter Clone, you’ll know what I’m using and why I’m adding things to it.

Sandra is available on Github at https://github.com/charlesmaxwood/sandra

Download 531.0 MB
Download (iPod & iPhone) 111.8 MB
Take the 2011 Readers Survey

{ 3 comments }

I’m working on another Cassandra demo, but didn’t have time to finish, so I decided to show you Ruby Koans. It’s a very interesting test-driven approach to learning Ruby. I hope you enjoy it.

Download 52.5 MB
Download (iPod & iPhone) 31.1 MB
Take the 2011 Readers Survey

{ 1 comment }

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 }

With the recent release of the Google Plus beta (ask me for an invite if you want one), I felt it appropriate to show a simple way to create a Like or +1 button for your Rails application. The app and concept is pretty simple, so I won’t worry about posting the code below.

Install:

gem 'make_flaggable', :git => 'git://github.com/cavneb/make_flaggable.git'
bundle install
rails generate make_flaggable
rake db:migrate

Models:

class Article < ActiveRecord::Base
  make_flaggable :like
end

class User < ActiveRecord::Base
  make_flagger
end

Links:

https://github.com/medihack/make_flaggable
https://github.com/cavneb/make_flaggable

Download 93.4 MB
Download (iPod & iPhone) 43.9 MB

{ 6 comments }

Specification

  • Clicking a star rating turns on the stars to the left of the star I clicked.
  • Clicking a star submits the star rating.
  • When I refresh the page, the star ratings should be persistent.

We’ll be using Rails’ functions including:

  • form_for
  • hidden_field
  • Rails Helpers

We’ll be using jQuery functions including:

  • click
  • each
  • ajax

<code>
<% form_id = “movie_#{movie.id}_rating” %>
<%= form_for movie.ratings.last || movie.ratings.build, :html => {:id => form_id , :class => “star_rating_form”} do |f| %>
<%= f.hidden_field :movie_id %>
<%= f.hidden_field :stars, :id => form_id + “_stars” %>
<% end %>
<% (1..5).each do |i| %>
<li id=”<%= form_id %>_<%= i %>” data-stars=”<%= i %>” data-form-id=”<%= form_id %>”></li>
<% end %>
</code>

<code>
var set_stars = function(form_id, stars) {
for(i=1; i <= 5; i++){
if(i <= stars){
$(‘#’ + form_id + ‘_’ + i).addClass(“on”);
} else {
$(‘#’ + form_id + ‘_’ + i).removeClass(“on”);
}
}
}

$(function() {
$(‘.rating_star’).click(function() {
var star = $(this);
var form_id = star.attr(“data-form-id”);
var stars = star.attr(“data-stars”);

$(‘#’ + form_id + ‘_stars’).val(stars);

$.ajax({
type: “post”,
url: $(‘#’ + form_id).attr(‘action’),
data: $(‘#’ + form_id).serialize()
})
});

$(‘.star_rating_form’).each(function() {
var form_id = $(this).attr(‘id’);
set_stars(form_id, $(‘#’ + form_id + ‘_stars’).val());
});
});
</code>

{ 4 comments }