Showing posts with label rails. Show all posts
Showing posts with label rails. Show all posts

Some Rails Plugins Won't Install

If any of you listening are subversion-savvy, I'm getting the following error when I try and install select plugins:

svn: Can't connect to host '[some hostname]': A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

...Any clues?

It sure sounds like port-blocking, but I've installed other rails plugins just fine. I suppose it could be the case that the ones that work are using http, but I'm not sure.

I've also tried both hostnames and IP addresses.

...I'm just asking for a little lateral-thinking. If you have any, I'd appreciate it.

Cast of Characters


I thought I could use a little "trash" application here at work, where I could test out Ruby/Rails features without stepping on the toes of our other main products.

Rather than just make another "depot" application, I thought I would recreate a collaborative writing game that a friend I used to fool around with when we were both fairly young developers. The idea is simple: you can see the last line of text just fine, but the rest of the story is garbage.

Because I wanted to allow some level of continuity, I decided at the last minute to add the idea of characters, so before you post a line to the story, you must choose who is acting/speaking. This should at least avoid the somewhat-annoying habit of having characters appear in a story for two lines, then disappear. Other features are a "gibberish" engine that converts words into garbage by changing vowels and consonants independantly. The result is strikingly readable, if a little spooky. Also, you can attach an image to any given post (via a URI).

At the moment, there are no restrictions on who can post or how often, who can create how many stories, or the like. The login process is brain-dead, but password-protected. ...There is no logout. And presently, there is no way to "finish" a story, such that editing is locked and the real text is displayed (rather than the gobbledigook). I'd also like the ability to change how many lines are hidden/shown at any given time. I also thought it would be a neat feature to randomly pick a word or three from the last hidden line and show them, so you get a vague sense of what was going on. These would all be easy changes, but at that point, I got bored with it and just wanted to show off what I'd accomplished.

It took me about three hours, all said and done.

Sorry: you can't play. I don't have a static IP at home, and I don't have a Rails host to put this on. ...I looked it up: it's only $5 a month... but finances are crazy tight at the moment, so I can't do this until we get a few things cleared up. (I don't want to go into the details.)

If you would like a copy of the source, though, I would be more than happy to oblige.

Thrown Down in the Dojo

With the release of Dojo 1.0, I thought it was time to pick up that particular torch, and add it to our project. It's quite sexy, what it can do.

So I spent the morning trying to get Rails to choke down the include tags (which, if you Google it, you'll see is non-trivial). Once that was working, I goofed around with a few forms, then abandoned the idea.

Yes, abandoned it.

According to Firebug, my load times on any particular page went from 281ms to over 2.1 seconds.

It sure does look cool, though. And if we end up creating some big Ajaxy page, where the user sits and doesn't leave, then I'll whip it out again. But in the meantime, it goes against the grain of what we're doing and is clearly too heavyweight.

Maybe someday I'll get back in the dojo.

A 1000 Blank White Cards Initial Migration for Rails

class FirstWhack < ActiveRecord::Migration
def self.up create_table :cards, :force=>true do |t|
t.column :title, :string, :null=>false # Name of the card. "Jumpin' Jesus on a Pogo-Stick"
t.column :img, :string # A fully-qualified URL or local filename. Null implies "blank"!
t.column :effect, :string # Psuedo-code. Ex: "modify 1 cards where target has tag 2" Optional
t.column :action, :string # Describe the effect. "Play on a blue card--change the image." Optional.
t.column :points, :integer, :null=>false, :default=>0
t.column :player_id, :integer # Current owner, null is discards
t.column :game_id, :integer, :null=>false
t.column :created_at, :datetime, :null=>false
t.column :created_by, :integer, :null=>false # fk to players
end
create_table :tags, :force=>true do |t|
t.column :name, :string, :null=>false
end
create_table :cards_tags, :force=>true do |t|
t.column :card_id, :integer, :null=>false
t.column :tag_id, :integer, :null=>false
t.column :player_id, :integer # Who created it? If null, it was auto-added (ex: "blank")
t.column :created_at, :datetime, :null=>false
end
create_table :players, :force=>true do |t|
t.column :name, :string, :null=>false, :limit=>128
t.column :born_on, :date, :null=>false # So we know their age (and birthday?) - play will be youngest -> oldest
t.column :email, :string # Notification of turns. Optional.
t.column :img, :string # Full URL or local filename. Optional.
end
# Apparantly we've got a Catch-22, here: I don't yet have a Player object. Hmmmn.
# jr = Player.create :name=>"Jeremy Rice", :born_on=>Date.civil(1974,8,7), :email => "jrice.blue@gmail.com"
create_table :players_tags, :force=>true do |t|
t.column :player_id, :integer, :null=>false
t.column :tag_id, :integer, :null=>false
end
create_table :games, :force=>true do |t|
t.column :name, :string, :null=>false # Name of the game: "Teh Interwebs is 4 p0rn///"
t.column :current_player, :integer # Null until the game starts. Fk to players.
t.column :turn_order_sort, :string, :limit=>4 # Null for ASC, otherwise "DESC".
t.column :created_at, :datetime
t.column :started_at, :datetime
end
create_table :games_players, :force=>true do |t|
t.column :player_id, :integer, :null=>false
t.column :game_id, :integer, :null=>false
t.column :ready_to_start_at, :datetime # Null until the player has created their first 5 cards.
t.column :joined_at, :datetime
end
# This will store each play in a game. Useful for undos, but might also produce a kind of history.
create_table :plays, :force=>true do |t|
t.column :player_id, :integer, :null=>false
t.column :game_id, :integer, :null=>false
t.column :card_id, :integer, :null=>false
t.column :comment, :text # Jibe from the player; optional.
t.column :targets, :text # Not yet sure how I'll store this, but it'll be an array of objects.
end
end

def self.down
drop_table :cards
drop_table :tags
drop_table :cards_tags
drop_table :players
drop_table :players_tags
drop_table :games
drop_table :games_players
drop_table :plays
end
end

Ajax Scaffold on Rails with SQL Server

I was working on Rails today.

Using SQL Server isn't the nicest thing, with Rails... support is sub-par, but growing. One nastiness I ran into today was after installing ajax_scaffold_generator, having exceptions thrown when it comes to showing the list view. So... I dug around and discovered that sqlserver_adapter (part of activerecord) was recently patched to fix some pagination problems. So I grabbed the new version and put it in place:

C:\ruby\lib\ruby\gems\1.8\gems\activerecord-1.14.4\lib\active_record\connection_adapters

Then you can install the package:

ruby gem install ajax_scaffold_generator

...when it's done, run (in your project directory):

ruby script/generate ajax_scaffold Object

(or whatever object you want instead of "Object".)

Very nice.

Ruby

I got paid (for the first time) to write Ruby today.

A co-worker and I set up a new publications database and used Rails to get up the scaffolding for the website.

Of course, the only real "code" I wrote was to display a list of authors related to a partiucular title. I don't have the code in front of me, but it was something like:

<% for author in @title.authors %>
<%= link_to author.fname+' '+author.lname, :action=>'author_show', :id=> author.id %><%= ', ' unless author === @title.authors.last %>
<% end %>

I had to create the title_controller.rb's "author_show" method, which was something like:

def author_show
redirect_to(:controller=>'author', :action=>'show', :id=>params['id']);
end

...And aside from a "has_and_belongs_to_many" from titles to authors and vice-versa... that was all I had to write to get that functionality (of displaying all the authors for a title).

Of course, I'm a little disappointed that I had to put that "<%= ', ' unless author === @title.authors.last %>" in there. Really what I wanted was a ".join(', ')", but I couldn't get that to work: I'm not familiar enough with link_to and... well... with tying bits and pieces of ruby together.

Even still, the way it is is very readable. (Yeah... that's my excuse, and I'm sticking to it!)

The co-worker that I was helping was very impressed with the amount of ground we covered in the three hours we worked on it, anyway. ...Note that over half that time was wasted trying to connect to the SQL Server database... (Turns out there is not trick to it, just set the type to "sqlserver" and fill out the rest of the fields intuitively!)

On the down side, I was so wrapped up in the project that I totally forgot that I had a date with my wife for lunch--and I was away from my desk, so I didn't get her calls. ...So I'm in the doghouse, now. : | D'oh.

Weekend Update

Three things to report:

My son and I played three games this weekend. The first was one called Heroscape, and it was the most age-appropriate of the three (we played the "simple" version). I won, but just barely. The second was Dungeons and Dragons Miatures. ...The rules were a little too hard, but he did quite well. And I have to admit: he was faster than I was with the math! He kicked my butt. The third was Star Wars Miatures. He mauled me.

Anyway, this is newsworthy only because I've long felt guilt about not spending enough time "playing" with my son. This was a good start. I have to say I was impressed... he lost the first game very gracefully, he learned the rules fairly quickly, and he didn't do anything overtly "stupid", tactically speaking. He did get overly excited about the game, especially the last one, where he was really wiping the floor with me. ...but that's him: he can't sit still and can't stop talking. ; )

I had a medical "slip" this past week. Last week, the doctor upped my dosage of Levothyroxine from 100 micrograms to 125. ...I had been having these occasional episodes of lightheadedness and chest "weirdness", that I couldn't quite describe. After the dosage changed, I started having them all the time. (Well, okay, several times an hour.) I noticed that if I took my pulse while these were happening, my heart-rate was all screwy. So I looked up cardiac arhythmia on Wikipedia and, lo and behold, this is a symptom of hyperthyroidism.

But it didn't stop there. Since I work with a dozen pharmacists, I asked around about it. I also work with six people who either have a thyroid imbalance or their spouse does... and I learned that the way my doctor was giving me my medication was prone to heart palplitations: this is why people normally start at very low levels of thyroxine and titrate up to the levels they need.

Anyway, I called the doctor--we was out--but another doctor at the office told me to go back to 100 micrograms, and to make an appointment for when my regular doctor gets back. I did both. The heart palpitations are completely gone now (three days later). All is well again.

It looks like I really will be using ruby at work! On Thursday, I had a meeting with all the other programmers about a new web-project that the center will be doing, and I argued for heavy use of Ajax. I showed my own code as an example--they were all very impressed--and then I showed the programmer who will head the new project how I was accomplishing it with Cold Fusion. I went on to explain a lot of the leg-work I was doing in CF was built-in to Ruby on Rails, and he was totally sold. We will pilot Rails next week, doing some pair-programming.

Not only that, but the center's lead deveopler asked me to schedule some sessions with the other programmers to teach them Ruby (and Rails), so we can all add it to our arsenal.

(I don't know if I logged this or not, but we recently switched from Visual Basic to C#, and have started pair-programming in it: it's insanely fun. Ruby will only be an improvement.)

With RubyCLR coming to maturity, and Ruby in Steel another option, I can't think of any reason why we wouldn't use it. A lot.

The lead programmer and I have already been joking about using IronPython (their main site isn't up at the moment). I wouldn't mind that. ...Though I admit, I've got a bias for Ruby at the moment. ;)

Perl is beautiful, and I will always love it... but I have come to admore "real" OO programming, and while it's possible in Perl... it's hackish.

Perl 6, of course, will be a god-send. ...But I am not holding my breath.

Ruby is, IMO, currently the most ideal scripting language. Java's bulky, and C# is... well... Microsofty (but I do enjoy it). C++ still reigns supreme in terms of speed and capability... but I'm a high-level programmer. ...But, most importantly, Ruby is fun, and has an amazing community. And Rails is pretty slick. : )

A Possibility

A co-worker just asked me to look at his database ERD--a butchered version of Northwest Pubs (one of Microsoft's example DBs), to handle VA publication references.

I thought, "whoa, he could have this up in running in a few hours with Rails." I've been trying to sell rails to this co-worker for over a year now, so when I told him my thought this morning, he was prepared for it: ruby wasn't a foreign concept to him anymore. His response was "that's what I wanted to hear!".

We're scheduling some pair-programming to give it a whack in the near future.

Another co-worker overheard the conversation. ...He then asked me what I thought about another web-application...

[writhes hands insidiously]