Foliosus Web Design LLC: Your website done right

Posts in "ruby on rails"

RailsConf '09: What professionalism is about

May 12 ’09

Robert Martin's keynote at RailsConf this year, though ostensibly about SmallTalk, was really about professionalism. Many people are talking about it, but I think there's part of the message that everybody missed. Read the rest …

HOWTO: Create a new link by munging the current URL in Rails

Mar 20 ’09

I've been working on a restful app that allows very complicated searches. I've been composing scopes to build the searches, but that's another post. All searches use the index action of the resource's controller. I wanted to offer RSS feeds for every possible search, to allow users to really get only the information they are interested. But I couldn't figure out how to generate the custom RSS feed link easily. I could have gone through my list of scopes, and then re-created the URL with :format => :rss, but that's not very DRY. It turns out that there's a much easier way. Read the rest …

Change the prompt in the Rails console

Mar 04 ’09

At work, I frequently find myself in the situation of having two or three or more console windows open, working on multiple apps in different environments. After almost getting myself into trouble on several occasions, I decided that I'd rather have the Rails console tell me what environment I'm running in. Read the rest …

HOWTO: Use a Rails model with an Oracle public synonym

Nov 11 ’08

The title of this post is somewhat misleading. It turns out that you can't use Oracle public synonyms with Rails, because of how ActiveRecord obtains information about the fields in its models.

The problem

Let's say you have the following model:

class User < ActiveRecord::Base
end

If you have a public synonym in your database called users AR will fail, with an error message about how it can't get column information for the users table.

Why is that?

Well, AR queries the all_tab_columns view to get the column list, with something like this: Read the rest …

HOWTO: Get up and running with PostgreSQL and Ruby on Rails on Leopard (Mac OSX 10.5)

Oct 01 ’08

I ran into this problem at work today: for once, instead of Oracle, it was time to use a PostgreSQL database. I've never used PostgreSQL before, so this was all new territory to me.

Looking around online, I found several pages that describe how to do this with MacPorts. But I don't have MacPorts, and I don't want it, since PostgreSQL ships binaries with an installer for Mac OSX. I want something simpler, anyway.

It turns out that the solution is fairly easy: Read the rest …

HOWTO: Install mysql gem on Leopard

Sep 12 ’08

A while ago, when I upgraded to Rails 2.0, I started getting the annoying "upgrade to the real mysql library" message every time I did anything with rails from the command line. Running rake tasks, running tests, opening a console session, I'd always get the error. When I would try to install the gem (sudo gem install mysql) I'd get the following error: Read the rest …

Connecting Ruby on Rails to Oracle on an Intel Mac in Leopard, take 2

May 05 ’08

Since I posted the first version of this article, there have been a couple of changes. The biggest one is that Intel has released Intel Mac versions of the InstantClient. Woohoo! That makes the previous version rather too complicated, so I've updated it here. This tutorial assumes that you're using Rails 2.0 or greater. If you're starting from the setup we had before, and you want to fix it, start with the cleanup instructions at the bottom, and then come back here. Read the rest …

HOWTO monkeypatch Rake: overriding a Rake task

May 05 ’08

I know that some people really don't like monkeypatching, and I see why. But sometimes it's just unavoidable. Recently at work we came across a situation where the standard rake db:schema:dump task just wasn't working. So I started by writing the new version of the rake task that I wanted:

namespace :db do
  namespace :schema do
    desc "Create a db/schema.rb file"
    task :dump => :environment do
      require 'active_record/schema_dumper'
      puts "Creating schema:"
      File.open(ENV['SCHEMA'] || "db/schema.rb", "w") do |file|
        ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
      end
    end
  end
end

This task as shown does exactly what the default rake task does, except for the puts line. Let's just pretend that it's a radically different and wonderful version that solves world hunger and raises your children. Now, if you drop this into a rakefile in your app's lib/tasks directory, and then you run rake db:schema:dump --trace you'll notice that the schema.rb file gets created twice. What the??? Read the rest …

Call URLs on your app from the Rails console

Feb 06 ’08

Here's a neat trick I just learned from Obie Fernandez (The Rails Way, p. 30): you can see what your Rails app's HTML output is from the console. To make this work you have to fool the app into thinking that there's a request coming in by setting some environmental variables, and then call the dispatcher.

But wouldn't it be nice to have a single method call, that uses url_for syntax?

Read the rest …

A rake task for setting up new Rails projects for Subversion

Jan 31 ’08

One of the more annoying things about using Subversion for source code control when using rails is that every time you start a new project, you have to go through this dance to get the new project's Subversion setup done. Really, this means that you're repeating yourself every time you start a new project, so in the interest of DRYness, it seems like you would want to script this. Even better, you could just setup one canonical project that you checkout instead of running rails my_new_project.

I've found several pages on the internets that discuss how to do a good subversion setup, and they each had their strong points. I've combined their approaches into a method for making a canonical blank app.

Read the rest …

About the author

Brent Miller is the owner and principal web designer of Foliosus Web Design LLC in Portland, Oregon. He enjoys food, plants, and the color green. If you are interested in hiring him for web work, please contact him.

Categories

Plant of the day

Unknown sp.

Unknown sp.

Fresh photos