Hello World: Rails 3.1

Been a while.  I’ve been working on other things like my daddy blog and some other nerd side projects here and here.

If you aren’t a) at least a little nerdy and b) interested in Ruby on Rails, stop reading now.  You won’t care about this.

I am relatively new to the Rails world (October of 2010) but have plenty of experience with lots of other stacks and just got back last week from RailsConf 2011 in Baltimore.  There was a strong focus at the conference on the upcoming Rails 3.1.

So this week at work I started playing with upgrading our Rails app to Rails 3.1.rc1.  There isn’t a whole lot of documentation about 3.1 yet as expected, its not even finished, but most of the documentation that I’ve found relates to creating new apps, not upgrading existing apps.

I figured I might share my thoughts and experiences so far because by all accounts, 3.1 introduces lots of great changes.

Again, I’m certainly no expert and I’m almost positive I’ve done some things wrong but as of right now, we pretty much have an upgraded Rails 3.1 app.  Go take a look at the official release for the basic info.  I will not go into much detail here about actually using CoffeeScript or Sass.  Those will be in future posts as I use them more.   This is going to be more about “upgrading your infrastructure”.

Arguably the biggest new feature is Asset Pipeline.  To take advantage of this, it basically meant manually creating an assets directory in the /project/app directory and then again in the /project/vendor directory.  Inside those directories, I created images, javascripts, and stylesheets directories (just like what you had in your public directory.  Now for the fun…

We had our share of JavaScript libraries, starting with jQuery.  jQuery is now the default JS library so I got rid of our versions as well as rails.js.  Then it was time to make choices.  Application-specific JS files went into /project/app/assets/javascripts and the additional jQuery libraries went into /project/vendor/asssets/javascripts.  The same types of changes for the stylesheets and for images.  By this point, we had nothing left in the public directory except for some empty directories.

Nothing will work yet.

Configuration changes to be made in your Gemfile

  • Change your gem ‘rails’ to gem ‘rails’, ‘3.1.0.rc1’
  • Add the following gems for the Asset Pipeline:  ‘sass’, ‘coffee-script’, ‘uglifier’
  • Make sure you have the ‘jquery-rails’ gem
  • Ran into some problems with dependencies for the omniauth gem and commented it out for the moment

Run the typical bundle install.

In application.rb you need to add:

config.assets.enabled = true # Enables the Asset Pipeline

In development.rb I commented out the config.action_view.debug_rjs = true line.  Sometimes you get to a point where you just want to see something work.

To actually reference the assets correctly, a few more changes to go…

We were using application.js as the global JS file.  I moved all that JavaScript into a new /project/app/assets/javascripts/project.jsapplication.js can now be used as the aggregator.  At runtime, all of your JS libraries will be collected into this file and.  First, in your layouts, or wherever you do your JavaScript includes, you just need this one include:

<%= javascript_include_tag “application” %>

Here’s what our application.js looks like (this is the whole file):

//= require jquery
//= require jquery_ujs
//= require_tree ../../../vendor/assets/javascripts/
//= require “project”

Notice the quotes around “project”.  That is similar to the “old” way where it is referencing a file, any file in any of the asset directories, without the extension.  Add as many as you like.  If you just want to load all the JS files in the directory, you can just do:

//= require .

Keep in mind, if the order that the files are loaded matters, you need to add them manually like the “project” reference.

The key thing to know here is that whatever you list in this file will be loaded on every page so if you have more controller-specific JavaScript libraries, the old-fashioned way still works:  Add another <%= javascript_include_tag “other_library” %> to the views you want.

You now need to do some similar stuff for stylesheets.  The concept is the same.  The syntax is a little different, of course, based on CSS:

/*
*= require_self
*= require “mywidgets”
*= require_tree ../../../vendor/assets/stylesheets/
* require_tree .
*/

You then add your <%= stylesheet_link_tag “application” %> just like for JavaScript.

And you’re ready to go…

 

 

We love to fly and it shows

Maybe I’m out of touch.

I heard a radio ad this morning proclaiming a new great benefit for Delta customers who get a Delta Premier American Express something-or-other card. Ooh, a great new benefit…I like the sound of that. Ready for this great new benefit:

“If you sign up for the credit card and become a member, your 1st piece of luggage is free!”

Impressive. This is a head-scratcher for me. I haven’t traveled via airplane much recently but I know that everyone is charging for luggage and everything else. I’m sure it’s just a matter of time before I’m required to bring my Fastlane transponder with me on the plane so that when they fly through the new floating air tollbooths I can get charged appropriately.

It’s one thing to raise prices and charge for everything and give me some reason. At least you are pretending to be “honest” with me. It’s another thing to pretend that you are actually going out of your way for the customer while treating us like we’re complete idiots.

It would sort of be like Apple saying that they’ve invented this new great feature for their iPhone OS called “Multi-tasking”.

Look, run your business. Do what you need to do. Don’t treat me like an idiot and pretend like you’re doing me any favors with your faux-addon-benefits which were part of the “ah, yeah, obviously that’s included” category not too long ago.

By the way, I’d rather pay $250 for my ticket and have my luggage travel for free than $200 and then have to pay $50 for my luggage. Then I don’t feel like I’m being nickel and dimed.

Awful name. Incredible phone.

I have owned my new phone for just over 24 hours and where I probably shouldn’t say it’s the best phone ever, I will.

I had been using a Blackberry Storm prior to last night’s purchase of HTC’s Droid Incredible. This was my first experience with the phone:

My wife and I were on our way to see a community theater production in Concord, MA. We were at the Verizon store and were going to finish there and head right to the theater. The salesperson at the store handed me the Incredible after she had tranferred my contacts.

I found the search “fixed” button and typed the name of the theater company. I got the Google search results, touched the Map link and then the Navigation link. Just like that, I had turn-by-turn navigation to the theater. This whole process for me took less time than it took to type this paragraph. I had no documentation and had not used the phone.

It was intuitive and fun and cool.

2 phones ago I had an iPhone. I never really fell in love with it. That was at the beginning of it’s run. I know it’s much better now. The Storm was great for email but lacked the coolness or application support that I know the iPhone has. I wanted something in the middle and I think it has arrived.

It’s a geeky-fun phone that doesn’t feel like it’s meant for geeks. The Android Marketplace has all the apps I need, for free…I feel like I have a phone that will literally do everything I need it to do and I don’t feel dirty because I’m not supporting Apple’s closed “We know better than you” platform (I am writing this on my iPad so I still feel a little dirty).

Love it.

The name is awful. I actually felt embarrassed when I showed people today and they asked what it was called. The phone is the best out there for me. Until it isn’t.

I think I’ll change my name to Matt Awesome.

Not a Fan

To whom it may concern:

99% of the time, if you have to ask me to be your fan, I’m probably not. Thanks to Facebook’s awesome fan mechanism, I can now be annoyed almost constantly by people who think I should become a fan of theirs.

I especially appreciate the following paraphrased Facebook interaction:

“Hey, I think you should become a fan of my sprocket company.”

“No.”

[next day]

“Hey, not sure if you accidentally answered last time but I think you should become a fan of my sprockets company.”

“Ignore.”

[next day]

“I can’t remember if I asked you to be a fan of my sprockets company, so you should, ok?”

[unfriend]

You: leave us alone. We all know you just invite all your “friends” so there is no way you forgot to ask me. If I show up again, that means I said no. No means no. You don’t want me to be your fan anyway. You just want my “friends” to see that I’m a fan so they might become a fan too. Leave us alone.

Facebook: learn. How about an option to ignore invitations from someone who is abusing the spirit of the site.

If I have something I think is important to share, it goes here, or in my status on Facebook, or on Twitter. You can consume it if you want and if not, well that’s your loss.

Sunny Days

My wife and I took my older daughter (who just turned 2) to see Sesame Street Live this morning. This was her first live show and we weren’t sure how she would deal with all the glitz of the Great White Narrow Way.

Now, Noa watches Sesame Street so we had that going for us. She also dislikes loud and chaotic “situations” so we didn’t have that going for us. The show was at 10:30am and we knew there would be a large number of kids so we had that going for us. She also really dislikes loud and chaotic “situations” so…

We arrived at the arena and got to our seats with about 10 minutes to spare. So far, so good. I don’t know it the whole thing was just confusing or if she recognized the Sesame Street sign or if the amount of other kids around made her feel comfortable but she was calm, cool, and collected. We had been explaining to her for about a week what we would be doing but I don’t think that it really clicked. Then again, maybe it did.

Then…the voice of Big Bird started talking to us and told us the show would be beginning in 3 minutes. That caught her attention. It seemed like she wasn’t sure what was gonna happen. She is sitting in her very own chair, feet barely making it to the edge of the seat. Her weight barely enough to hold the seat down.

The house lights go down.

She looks a little on edge/confused.

Big Bird hits the stage.

She throws a finger (pointer, not middle) towards the stage and shouts, “BIG BIRD!” with an ear-to-ear grin. One at a time the other characters make their way out and she is announcing them all. She is having the time of her life. My wife and I are elated but neither of us can figure out why. I suspect it has something to do with us both realizing that we have a bonafied little girl.

The show was great. We all had a great time. We get in the car to come home and ask her what her favorite part was. She said matter-of-factly, “the chipmunks.”

I don’t know what show she was watching but I suppose it doesn’t really matter does it?

2nd 1st

I am a 2nd child. It’s not always easy to grow up in that position. My sister is just about 3 years older than I am. When I was born she was old enough to have an established routine and a fair amount of independence.

My older daughter had just turned 1 when my younger daughter was born. She had not learned to walk yet, was barely talking yet, and really didn’t have much independence. I’m sure that it wasn’t always easy competing for mommy and daddy’s attention for either girl.

The good news is that neither girl will remember a time when they didn’t have each other. They won’t know a time when they didn’t have someone to accidentally cuddle with or learn to share with. The good news is that even though being the 2nd sister has initially been a lot of “stuff the 1st sister does,” their interests and personalities seem to be different and that’s been really cool to watch.

We’ve made it through our 2nd 1st year.

They have both made it through their 1st years.

Happy 1st Birthday Sasha.

Cliffhanger

So I was watching this show that had a really captivating plot. I am not going to go into too many details here because I don’t want to spoil it for you. I will say this: the plot was a little all over the place and included action, adventure, drama, celebrity cameos and more. It still kept my attention for what felt like an entire night.

It seemed we were nearing the conclusion of the story and then blammo!

I woke up. Well how does it end? I kept trying to fall asleep again to find out how but it seemed to be a futile effort. Then I realized I was the screenwriter, director, and producer. I should already know how it ends.

But I don’t.

And that sucks.

And then…

iThink iLike

Maybe the addition of the iPad to my geek arsenal will motivate me to blog more. Maybe.

New Year's Resolution

My resolution for 2010 is to write more blog posts.

Hey, if people haven’t taken down their Christmas lights yet, I can only imagine they are just leaving them up in preparation for next Christmas. If we’re going to plan ahead, I might as well make my resolutions in advance too.

Filling out the forms

So I’m at the doctor’s office the other day filling out the forms. Patient’s name. Patient’s address. Nice and easy.

Relationship to the patient: Father.

That’s gonna take some getting used to.

Subscribe to RSS Feed Follow me on Twitter!