How To Start A Rails Edge App The Easy Way

January 4th, 2009

There’s a lot of cool stuff pooring in about what’s new in Rails Edge (which will become Rails 2.3 and/or Rails 3).

Most likely you can’t wait to get started with these new features, especially when you’re about to start a new project, which doesn’t have to be stable yet, but will be by the time 2.3/3.0 come out. This post shows you the way to create a new Rails app based on the most current Rails code, also called Edge Rails.

Let’s go…

mkdir -p myapp/vendor
cd myapp
git init
git submodule add git://github.com/rails/rails.git vendor/rails
git commit -m "Frozen Rails Edge as submodule"
ruby vendor/rails/railties/bin/rails .
# Add generated files to git, and code on...

First, you create a new directory for your app, including the vendor directory. Easy, right?

Next, you initialize a Git repository for your empty project. We’ll be using Git to track the remote Rails Edge code. Stay with me.

By adding a Git submodule we tell git to clone the code from git://github.com/rails/rails.git into the vendor/rails directory. Nice! If you check the current git status with git status you see git has already staged two files for you, .gitmodules and vendor/rails. Commit them now to attach the submodule to your local git repository.

Git will not automatically update your submodule, you’ll have to do that by hand. I’ll show you this in a minute.

With vendor/rails containing Rails Edge, you can now generate your Rails Edge application. In you project directory (myapp/), you call ruby vendor/rails/railties/bin/rails .. This will generate a new Rails Edge application in the current directory.

Now it’s up to you to create a fitting .gitignore file and commit the files to your repository.

That’s all, you now have a new Rails Edge application. Try ruby script/server to see it all in action. Enjoy!

Cloning your project

At some point you’ll push your myapp project to a remote git server. When you clone a fresh copy, you’ll have to initialize the git submodules. This is quite easy:

git submodule init
git submodule update

Updating Rails Edge

As I said earlier, Git will not keep your submodules up-to-date for you, but will stick with the revision you added. To keep track of Rails Edge’s progress, you’ll need to update the submodule. This is done like this:

cd myapp/vendor/rails
git remote update
git merge origin/master

This will update your Rails Edge code. Make a commit, stating you updated the code!

After updating Rails Edge, you may want to update your rails application (like javascript files, config files etc).

rake rails:update

Good luck! And happy coding!

Please share the love of this post by bookmarking it, and sharing it with others. Thanks!

  • Digg
  • del.icio.us
  • description
  • Reddit
  • Facebook
  • E-mail this story to a friend!
  • TwitThis

, , , , ,

Twitterlicious!

December 27th, 2008

A bit late, but “Merry Christmas” everyone!

I’m on Twitter lately, so feel free to check and follow. It’s a also a nice way to keep up-to-date about new articles on Ariejan.net.

Hey, that’s all for now. And if you don’t come back here this year: “Happy New Year!” - Cheers!

Please share the love of this post by bookmarking it, and sharing it with others. Thanks!

  • Digg
  • del.icio.us
  • description
  • Reddit
  • Facebook
  • E-mail this story to a friend!
  • TwitThis

Google FriendConnect now on Ariejan.net

December 3rd, 2008

Well, I just got invited for Google FriendConnect! Let me tell you a bit about FriendConnect.

With FriendConnect you can easily join Ariejan.net. See of it as a pool of Ariejan.net visitors or fans if you like.

Once you’ve joined up (with your google account, for example) you’ll be able to interact more closely with Ariejan.net. In the case of Ariejan.net you can share your thoughts with other Ariejan.net visitors. Just vent your frustration about Linux or let others know what Rails project you’re working on.

Another benefit for you is that you can see what sites other people have signed up for as well. This way you’ll be able to get a list of sites that Ariejan.net visitors like as well. You might compare it with Amazon’s “other people also bought..” feature.

The big benefit for me is that’s it’s nice to see the list of fans/visitors growing. After all, that’s what I’m keeping a blog for after all.

In the future I’ll be able to add other widgets to Ariejan.net. This allows for other features to appear on Ariejan.net and a better over-all user experience.

You may want to read more about Google FriendConnect and OpenSocial.

Please share the love of this post by bookmarking it, and sharing it with others. Thanks!

  • Digg
  • del.icio.us
  • description
  • Reddit
  • Facebook
  • E-mail this story to a friend!
  • TwitThis

Export CSV directly from MySQL

November 27th, 2008

How ofter were you asked by a client for a CSV (or excel) file with data from their app? I get asked that question quite often, so I wanted make the process as easy as possible. And guess what? You can create CSV files directly from MySQL with just one query!

Let’s say you want to export the id, name and email fields from your users table to a CSV file. Here is your code:

SELECT id, name, email INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'
FROM users WHERE 1

Well, if you know MySQL, you’ll know how to customize this query to spit out the the right data. Your csv file can be found in /tmp/result.csv

Make sure your MySQL server has write permissions to the location where you want to store your results file.

Please share the love of this post by bookmarking it, and sharing it with others. Thanks!

  • Digg
  • del.icio.us
  • description
  • Reddit
  • Facebook
  • E-mail this story to a friend!
  • TwitThis

, , ,

SQL: Ordering with NULL values

November 14th, 2008

First seen at Kabisa Blog: SQL: Ordering with NULL values

This post tells you how to sort NULL values in a column to the bottom and sort the remaining non-NULL values.

This is really great in combination with LEFT JOIN queries that may yield NULL values.

Please share the love of this post by bookmarking it, and sharing it with others. Thanks!

  • Digg
  • del.icio.us
  • description
  • Reddit
  • Facebook
  • E-mail this story to a friend!
  • TwitThis

, , ,

RSpec’ing with Time.now

November 5th, 2008

I’m currently writing some RSpec tests that use Time.now.

I want my model to calculate a duration and store the future time in the database. I’ve already specced the calculation of the duration, but I also want to spec that everything gets saved correctly. Here’s my first spec:

it "should do stuff" do
  m = Model.create()
  m.expires_at.should eql(Time.now + some_value)
end

This fails.

It fails because Time.now is quite accurate and some milliseconds have passed between the two calls.

So how do you test this kind of behaviour? Get out your gloves, because we’re going to start stubbing!

What you need to do is stub out Time#now to return a constant value within this test. This way, both calls will use the same Time.now value and thus yield the same result. This in turn makes your test pass (if the saving goes well, of course).

it "should do stuff" do
  @time_now = Time.parse("Feb 24 1981")
  Time.stub!(:now).and_return(@time_now)
 
  m = Model.creat()
  m.expires_at.should eql(Time.now + some_value)
end

Please share the love of this post by bookmarking it, and sharing it with others. Thanks!

  • Digg
  • del.icio.us
  • description
  • Reddit
  • Facebook
  • E-mail this story to a friend!
  • TwitThis

, , , ,

BaseApp: a quick start for your Rails App

September 28th, 2008

For the impatient: http://github.com/ariejan/baseapp

Got issues? Feature requests or patches? http://baseapp.lighthouseapp.com/

Every Rails developer has at least once developed an application that needed user authentication and some basic UI features like tabs and a sidebar. Ask yourself now: “how often have you installed and extended the restful_authentication plugin?”.

Yes, I have done it quite a few times and everytime I find myself writing the same code over and over again. User login, password reset, ‘forgot password’ functionality. I’ve build the same basic UI over and over again. Added administrator users and roles.

Are you tired of doing the same old things over and over again? I was! So, I created BaseApp.

BaseApp is a Ruby on Rails application which contains a lot of code you want in your project by default. To give you an idea of what is does out of the box:

  • User Authentication including password recovery, account activation and account suspensio.
  • Admin interface where the admin user can easily manage users and tweak app settings
  • Default CSS-based UI with tabs and a sidebar. Very acceptable by default and easy to customise.

BaseApp is currently based on Rails 2.1.1. And although it’s a pretty complete package and ready to be used for your next project, it still needs a bit of work. Check out the README for features that should be in BaseApp.

Of course, BaseApp is open source so fork a copy at the GitHub and send me those patches (of pull requests)!

There are tons of feaures that can be included into BaseApp, so the next big thing is to include some sort of configuration that allows you to disable/enable certain BaseApp features.

So, go right ahead! Use it! Fork it! Send me those pull requests!

Please share the love of this post by bookmarking it, and sharing it with others. Thanks!

  • Digg
  • del.icio.us
  • description
  • Reddit
  • Facebook
  • E-mail this story to a friend!
  • TwitThis

, , ,

JRuby with Thomas Enebo

September 3rd, 2008

This morning I attended another JRuby talk, this time with Thomas Enebo. It turned out to be, almost default, Sun JRuby talk.

There was one interesting difference, though. Normally we are shown how to run Ruby on Java and how to use Java components in our Ruby apps. Thomas took JMonkeyEngine (a java 3d scenegraph/game engine) and showed that he coded a simple game in Ruby, steering clear of the rather complex Java code.

This is, of course, another great feature of JRuby, you can code a “Java” app, and in certain places actually use Ruby to write cleaner or “easier” code.

Well worth the time!

Please share the love of this post by bookmarking it, and sharing it with others. Thanks!

  • Digg
  • del.icio.us
  • description
  • Reddit
  • Facebook
  • E-mail this story to a friend!
  • TwitThis

Panel Discussion with DHH and Rails Core Members

September 3rd, 2008

Yesterday evening we attended a panel discussion with DHH and Rails Core Members Jeremy Kemper and Michael Koziarski.

DHH elaborated on default choices (like database, templating system and test suite) after being asked if Rails would switch over to RSpec instead of TestUnit. The answer was that Rails offers several defaults, which should suffice for new and basic users, who don’t know about all options and just want to get started. More experienced users will generate a taste for different components and Rails should provide for easy integration of these components if needed.

All in all there wasn’t any really new stuff to be heard, but a nice gathering non the less.

Please share the love of this post by bookmarking it, and sharing it with others. Thanks!

  • Digg
  • del.icio.us
  • description
  • Reddit
  • Facebook
  • E-mail this story to a friend!
  • TwitThis

JRuby with Nick Sieger

September 2nd, 2008

Welcome to RailsConfA tutorial on JRuby with Nick Sieger holding your hand is just great. This guy knows JRuby inside-out and he has an answer to even the most difficult of questions.

After a short 15 minute introduction, Nick left us with our Rails app to start it with JRuby on a mongrel. I’ve been toying around with JRuby a bit before, and this was rather easy. Some people, however, encounter some issues with their apps because of incompatible gems, like OpenSSL or RMagic which are not available for the Java platform. Luckily, there are some nice Java alternatives like JRuby OpenSSL and ImageVooDoo. My app didn’t suffer from these issues, but from what I’ve heard, these alternatives work great.

Next for the big work: creating a WAR file and deploying it. I’ve done this before, and it’s dead easy. In stall the Warble gem, warble your Rails app and deploy the resulting WAR file.

Nick also talked about the differences between using the JVM and Unix. The biggest differences are memory management and the creation of new threads/processes.

There are quite a few things that Rails and a Java app server have in common, like logging and session handling. In his sheets (I’ll link to those later), you can see how you can tune your Rails app to make use of these features and improve your apps performance (by not logging and keeping sessions in two different places).

Continuing on the performance of Glassfish/JRuby, Nick shows several graphs on how well JRuby performs. A lot of attention goes to Rails 2.2, which will be thread-safe and what it means for JRuby.

JRuby can run with 1 runtime and fill your CPU with threads to handle requests using native Java threads. To handle database connections, Nick Sieger has written a connection pooling component for ActiveRecord (to prevent every thread having it’s own connection to your database). An unreleased version of warbler was distributed that will allow you to set max_instances to 1. This will create 1 Rails instance and use threading in Glassfish. Of course, this is only useful with Rails 2.2.

This was altogether a great tutorial afternoon. Besides the basic warble-your-app-and-deploy-it, Nick provided a lot of interesting facts and tips about deploying to Glassfish. I already was enthusiastic about JRuby, but now I really have to get my hands on a decent server that will run Glassfish comfortably. This means at least at least 1Gb of RAM, so I think I have found at least one drawback of using JRuby.

Please share the love of this post by bookmarking it, and sharing it with others. Thanks!

  • Digg
  • del.icio.us
  • description
  • Reddit
  • Facebook
  • E-mail this story to a friend!
  • TwitThis

, ,