11.23.07
Posted in Uncategorized at 1:57 pm by Robert Horvick
I was checking RubyCorner’s updated feed and came across a post on rssHugger.com. In a nutshell the service (manually) reviews and categorizes submitted blogs into high-level topics (such as Technology, Finance and Humor).
It’s a similar idea to other web directories except that in addition to a site link it also provides a feedlink (which makes it similar to sites like bloglines, technorati, etc)
When I first read about the site what I expected to find was the ability to drill down to a category such as “Technology -> Programming -> Ruby” and subscribe to an aggregated feed of all the blogs in that category (similar to RubyCorner.com) but instead it is just a list of blogs with direct links to the site and feed (with less granular categorization - “Technology” exists but not “Programming” or “Ruby”).
Likewise I also expected to be able to subscribe to aggregated lists based on tags - but that does not seem possible either.
I also thought I might be able to create my own aggregated feed that I could share with others.
Finally I expected to be able to search blogs in a free-form way but the search link takes me to the directory list - not an actual search engine. That may be OK when there are only 23 registered blogs (with a goal of 250,000 the first year) - but as the number grows the ability to find interesting content is critical.
I don’t know what features are in the pipeline but right now it’s just a loosely categorized list of sites and feeds.
So to summarize - what it needs:
- More granular categories.
- Aggregated feeds by category
- Aggregated feeds by tags
- The ability to create my own feed lists (and give me some widgets to share on my blog)
- Meaningful search (for sites and posts)
- More sites.
Do a few of 1-5 and 6 will happen on it’s own.
Permalink
11.13.07
Posted in Uncategorized at 12:45 am by Robert Horvick
Last time I used ActiveRecord to persist basic tasks. On the list of features to implement was task state such as “New” or “Complete”.
I wanted to make sure that tasks were used definable and that the relationship at the class level did more than just expose an int that the user had to map to the proper state.
I started by defining the new SQL schema for tasks with states. The schema I created follows:
CREATE TABLE tasks (
`id` INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
`title` VARCHAR(255) DEFAULT NULL,
`state_id` INT DEFAULT NULL
);CREATE TABLE states (
`id` INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL
);
I did not realize that the name of the state_id column needed to be “state_id”. This makes sense and reveals a bit about how ActiveRecord works without the attribution requirements that other ORM systems have.
Next I added a new class for the State and added a relationship to Task. My thinking was “Each Task has one state. So use has_one.” It looked like:
class Task < ActiveRecord::Base
has_one :state
end
class State < ActiveRecord::Base
end
Marginally more experienced people probably already see the problem. The error I got when trying to run was:
Exception: Mysql::Error: Unknown column 'states.task_id' in 'where clause': SELECT * FROM states WHERE (states.task_id = 17) LIMIT 1
Ok - that’s backwards from what I expected. I assumed that since the Task “has_one” State that the ID being looked for would be the state ID, not the task ID. I did some digging and found that belongs_to and has_one are commonly confused cousins. And I found this blog post about it. So I need to change has_one to belongs_to and I need a has_many relationship defined as well.
Now the code looks like:
class Task < ActiveRecord::Base
belongs_to :state
end
class State < ActiveRecord::Base
has_many :task
end
That worked as expected (I should say “as hoped” since my expectation was that has_one would work). I have to admit I need more time to wrap my noggin around has_one vs. belongs_to.
Now with this in place I was able to write the following code:
state_new = State.create "name" => "New"
state_ip = State.create "name" => "In Progress"
state_complete = State.create "name" => "Complete"Task.create "title" => "Attend Raleigh Ruby Brigade November Meetup", "state" => state_new
Task.create "title" => "Attend mid-day scrum", "state" => state_complete
Task.create "title" => "Add state support to task list", "state" => state_ip
Task.find(:all).each { |t| puts "#{t.title} (#{t.state.name})" }
Which had the following output:
Attend Raleigh Ruby Brigade November Meetup (New)
Attend mid-day scrum (Complete)
Add state support to task list (In Progress)
Which was exactly what I expected.
Permalink