Posts filed under 'Railscasts Project'

A Rant

The market is really tight for ruby developers in Boston. Companies are often complaining that there is no talent to be found. But I think that’s mostly because companies are mainly looking for rockstars. And there are few of those to go around.

I understand that tech teams for startups need to be lean and effective, but if Boston rubyists want the community to grow they are going to need to convince their companies to invest in mentoring intermediate level programmers or even advanced beginners with solid experience in other realms.

Because I’ll tell ya, refining your skills on your own time after work is… hard. And as much as I try to find motivation through crazy ideas like the Railscasts Project and posting my little FaceBook app side project to github, I have commitments (my little girl) and obligations (my little boy) that demand my attention away from my laptop.

Is there really a work life balance for the ruby developer when the language and tools are evolving at such a frenetic pace? How the hell do these cowboys keep on top of it all?

Maybe they don’t know everything and just pretend they do… That’s a boy quality, isn’t it? And quite possibly, I know more than I may portray… That’s a girl quality, isn’t it?

How come I always feel like I just missed bus? (That’s a human quality, isn’t it?) Does anyone else feel this way?

The boston.rb community has been discussing various mentoring programs that they’d like to create. And I’m down for that. But honestly, I don’t believe it’s possible to learn how to speak French once a week and after the kids go to bed.

To become a true Parisian, don’t you have to go to France and immerse yourself in the language and the culture and the food?  So, isn’t it mandatory for the aspiring rockstar to work with a development team during office hours that practices agile slicing and dicing and are dedicated to testing and tasting their work, who ladle gems and libraries down their gullets like a sweet, creme based soup?

“That seelly Amerreecan weell neverr be eh true Parisian. No!”

I’m thankful to have a job that let’s me play with ror every day. Still, I wish more companies felt like @dpickett who recently tweeted:

I would place my bets on enthusiasm over talent any day. Invest in those that want to learn instead of those who think they know everything.

Add comment September 9th, 2010

Squashing

I laugh at my naiveté thinking that I could get any work done during vacation week with my two toddlers. Surely, I could watch and blog one episode a night? Surely?

Ha ha ha! Once my eldest was finally coaxed, cajoled and threatened into staying in her bed for the evening, I was a puddle of exhaustion without enough energy to even lift a martini glass to my lips. And if you are familiar with my relationship to vodka, you’ll realize how god damned tired this really is.

But today, the kids are back in school and I’m back at work… and it’s September. For me, this is a time of renewal… of starting over with a clean slate. And so…

The theme of the day is “squashing”.

Just before vacation, I completed a huge enhancement on a branch with pages and pages of commits made over a period of months. Helpful to me while I was in progress, but now that the work is complete… well it’s just plain too ugly to commit back to master. How many commits were there? I used this command to count them:
git log --pretty=oneline origin..mybranch | wc -l

Whoa. 61 commits for one enhancement. But thankfully I can use this tutorial from Bob Silverberg to use git rebase and squash all these commits into one.  Making my git log clean and neat.  And I like clean and neat.

So in keeping with this theme, I’m squashing the next three Railscast episodes which are all about creating administration screens.

“Why separate the public site from the administration side?”…Why indeed, Ryan. Scaffold generates new and edit views for my model, and episodes 19-21 shows us how to restrict access to them.

One railscast fan had an interesting question about this implementation:

This approach is pretty useful, but won’t it complicate caching down the line?

And Ryan’s answer:

True, it can make caching a little more difficult. A solution that I like is to create an “admin” subdomain for the site  admin.example.com) then just have the “admin?” method return true for this subdomain. This way you can easily cache pages without this subdomain.

What’s interesting about episode 20 is that Ryan shows us that a method implemented in the Application Controller can be used in a view via the helper_method method.  And then he goes on to introduce the before_filter.

Filters are pretty handy as demonstrated by this example.  But I’ve also seen filters abused horribly making it difficult for the maintenance programmer to track the flow of logic in an application.  As with everything, moderation is key.

In the final episode of the series, number 21, we learn about the restful_authentication plugin.

Back in the day… I implemented this plugin in a production app using the Restful Authentication with all the bells and whistles tutorial. But in 2010, we’ve got Authlogic, Clearance and other solutions for our authentication needs.

Yeah, okay… so these solutions might be much more than you need for a simple site. If so, use Ryan’s session example. But most plugins are so easy to implement! In fact, you can find an Authlogic starter application that includes Facebook integration. I’ve used it. Works awesome.

I prefer to use Authlogic even on my most simple sites because inevitably the client wants more functionality. And as I mentioned in my Security blog, I prefer to leave security management to the pros.

Add comment September 8th, 2010

Not Giving Up!

Oh Geek Mama… Why o why have you forsaken the Railscasts project? Is it your homage to _why last week?

No. I haven’t given up! I swear I haven’t! Big project at work. Working all weekend. Up until wee hours. Exhausted.

But I won’t let that stop me. Just slow me a down a little bit. But this week I’m getting myself back on track…. just in time for my planned vacation at the end of the month. Yay.

Ain’t nothing gonna break my stride
Nobody’s gonna slow me down
Oh no, I’ve got to keep on moving
Ain’t nothing gonna break my stride
I’m running and I won’t touch ground
Oh no, I’ve got to keep on moving

Yes. I admit it. I wanted to grow up to be a Solid Gold dancer.

Add comment August 23rd, 2010

A Show of Hands

Okay, people. I want a show of hands from everyone is Looping Through Flash messages as shown in episode #18:

    <% flash.each do |key, msg| %>
      <%= content_tag :div, msg, :id => key %>
    <% end %>

Instead of simply using the scaffold default which looks like this:

    <% unless flash[:error].nil? %>
      <div id="error"><%= flash[:error] %></div>
    <% end %>
    <% unless flash[:notice].nil? %>
      <div id="notice"><%= flash[:notice] %></div>
    <% end %>

I can’t say that I’ve ever seen Ryan’s example in the wild. In fact, I’m not even ashamed to admit that I”ve never seen anyone use the content_tag to create div tags in a view. Have you?

Admit it. You’ve forgotten all about content_tag. Damn, I’m glad I didn’t skip these early episodes!

Add comment August 17th, 2010

What Genius Created Checkboxes?

Good workout. Thanks for asking. Felt so yummy to be back in the gym. Wish my husband didn’t have evening clients so I could do it more often.

Unfortunately, my husband’s sporadic schedule combined with my kids’ relentless bedtime ritual means it’s impossible for me to keep a regimen going. Which is really ironic when you consider that he’s a personal trainer.

Anyway, back to rails related stuff…. I am freaking amazed how I learn something new with each episode. Tonight, I watched episode #17: HABTM (Has And Belongs To Many) Checkboxes.

Did you know that simply passing an array of values to your foreign key will auto-populate your join table? Ryan’s example illustrates this nicely via script/console:

>> p = Product.find(:first)
>> p.category_ids = [2, 3]

This code above automatically created the SQL insert statement below:

INSERT INTO categories_products('product_id', 'category_id') 
VALUES(1, 2)

Of course this only works with HABTM. You’re outta luck with Has Many Through and gotta roll your own. Still, this little shortcut is kinda nifty.

By the way… don’t you just HATE that empty checkboxes return NOTHING in HTML. In other words, when the checkbox is not checked no value is sent.

What a PAIN IN THE ASS! Sure there are ways to get around this, but what genius thought this up?

Yeah okay, there’s most likely some serious reason why this must be… but all I know is that I have to jump through stupid hoops and make an extra database call to get this to work properly. LAME!

4 comments August 16th, 2010

Debate

Okay… I got behind over the weekend. I skipped a couple of days and now I have to do double posts to keep up with my end goal.

But… I’ve also got to get to the gym. No really. I’ve got this wedding coming up and I think there’s a possibility that my ex-boyfriend who I haven’t seen in 15 years is showing up. Yeah.

After two kids it’s especially important to look sexy for this event… even though I think it might be a Star Treck/ Zombie theme.

Actually, I’m not sure if the groom is kidding about this or not. I’m hoping we do end up in costume. Although, honestly ladies trekkie costumes tend to be a little unforgiving.

Anyway, both endeavors are incredibly important. So I’ve really got to stay motivated. Thankfully, your feedback has been incredibly helpful. I’ve gotten some really great emails and comments from folks and I want to let you know that I really appreciate it.

Okay… gym now. Second post later. And if my dear friend does have a costumed wedding, I promise to bring mine to RailsConf!

Add comment August 16th, 2010

Give Me Something Slicker

In Episode 16: Virtual Attributes, Ryan shows us how to use virtual attributes to finess first and last name fields on a form. Of course, this is a very simplistic example. What about middle initials? Suffixes? Prefixes?

Every single time I try to use this feature, I find that usually there’s a very good reason these fields are separated in the database. Because mushing things together gets too complex when you start considering the edge cases.

Consider addresses or phone numbers. They’re straightforward enough until you start thinking globally.

I dunno. I’m sure there are brilliant examples out there of ways this can be used… but I’d like to see something a little slicker than just concatenating a name. got any examples to share?

Add comment August 16th, 2010

Find Me a Where Clause

I have always, always written out my find conditions the long way:

Post.find(:first, 
          :conditions => ['status = ? and active = ?', 1, 1])

And in some more complicated joins, this is entirely appropriate. But in Episode 15: Fun with Find Conditions, I’ve learned that you can specify conditions via a ruby hash:

Post.find(:first, 
          :conditions => { :status => 1, :active => 1 })

While the long way works just fine, what’s amazing to me is that this has been available since Rails 1.2. Where the hell have I been? Oh, yeah…. having two babies… but STILL!!

Fortunately,  Ryan’s got my back and I know (because I’ve been skipping ahead) that in Rails 3 the game changes and ActiveRecord provides a new interface for performing database queries.

Instead of :conditions we now use the where method, passing in the same arguments as we would to :conditions.

But whoa… let’s slow down there, Partner!  Baby steps.  Tortoise and the hare and all.

Add comment August 11th, 2010

Customizing Your Query

In the past, I avoided Performing Calculations on Models: episode 14 because I thought that under the hood rails was simply iterating through the array of active records returned from your sql query.

Turns out I was wrong.

There’s a much easier way than this to utilize the SQL functions and get the performance you want:

>> Task.find(:first,
             :select => 'SUM(priority)' 
             :conditions => 'complete=0')

In this episode, Ryan shows us the sql generated from his queries in the script/console and this:

>> Task.sum(:priority, 
            :conditions => 'complete=0')

creates the desirable sql query below:

          SELECT sum(priority) AS sum_priority 
          FROM tasks 
          WHERE (complete=0)

And of course this means that these methods are available through associations.  For example:

>> Project.find(:first).tasks.sum(:priority, 
                                  :conditions => 'complete=0')

is turned into this:

         SELECT sum(priority) AS sum_priority 
         FROM tasks 
         WHERE (tasks.project_id = 1) AND (complete=0)

What SQL functions are available?  Checkout the Calculations class in the api.

Add comment August 10th, 2010

Sessions are not caches

Is it just a coincidence that Episode 13 is fraught with danger?

In Dangers of Model in Session, Ryan devotes a whole episode to remind us not to store complex objects in our session.

Objects that are okay to store are very simple objects such as arrays, and strings, and ids, and hashes, and integers. But complex objects like models should be kept inside the database where the results are fetched every time.

There were a couple of comments on this post where folks noted performance problems as a reason to persist an object, but Ryan answers:

If you need a performance boost, look into a memcache solution.

But Ryan, I have to wait till episode #115!

Add comment August 9th, 2010

Next Posts Previous Posts


Pages

Tweets

Meta