Entries Tagged 'Ruby' ↓

Rails Bootup, Volume 1

Rails Bootup Logo

In Austin on Rails, whenever we’ve run beginner-focused meetings (which we have done from time to time), there has always been a great turnout for them. We’ve been debating about how to best structure the beginner vs. advanced topic mix for future meetings. It seems like a good idea to include some beginner content, but at the same time maintain the interest of our more experienced members.

One way that I am going to try to enhance the Rails knowledge within the Austin community is to offer a low-priced full-day workshop which will help get people up to speed on the basics of Rails. Several folks have directly expressed an interest in learning more about Rails in a more concentrated fashion than just a meeting here or there. So, a few of use have created what we are calling the Rails Bootup. It’s a introduction to Ruby on Rails served up in a single day workshop format. The day will be a mix of presentations, discussion, and hands-on work.

I am honored to be joined by Bruce Williams, Mike Perham, Edward Cruz, and Rob Rasmussen in teaching the event. These are experienced Rails developers and they are excited to share their passion for Ruby and Rails with you.

If this sounds interesting, please head on over and register for the event today (tickets go on sale on Monday, June 30th). The cost is $199 for one day and will take place on Saturday, August 2nd, in downtown Austin. The first Rails Bootup will be limited to 10 participants so the seats may fill up quickly. We want to keep it fairly small so that we ensure we are delivering a quality experience. Of course, this will be an iterative process and I am sure that there is much to learn as this experience unfolds.

sudo: no passwd entry for app! (Capistrano)

If you’ve recently upgraded to Capistrano 2.3+ like I have, you may run into a gotcha with Capistrano’s use of the “sudo” command for a nonexistent “app” user.

If you receive an error that looks like this:

*** [err :: server.hostname.com] sudo: no passwd entry for app!

Then you need to update your deploy file to include the following line:

set :runner, “deploy” (or whatever user you are running as for your deploy)

This error will then promptly go away! Yay!

Peek Inside Your Database From Rails Console

In our last posting, we looked at how to add a simple method lookup to irb. Another cool trick to have in your bag while consoling is to use an irb subsession to “become” another object. This can save some typing. As an example, say you are working in the console and you need to look up something about your database schema. It’s simplest to just do it in the console.

irb obj - Starts an irb subsession. If obj is given, it will be used as self.


Nomad:mephisto damon$ script/console
Loading development environment.
>> irb ActiveRecord::Base.connection
>> tables
=> ["assets", "assigned_sections", "cached_pages", "content_versions",
"contents", "events", "memberships", "schema_info", "sections",
"sessions", "sites", "taggings", "tags", "users"]
>> columns('assets').collect(&:name)
=> ["id", "content_type", "filename", "size", "parent_id", "thumbnail",
"width", "height", "site_id", "created_at", "title", "thumbnails_count",
"user_id"]
>>

To kill the subsession, just use ^D or quit.

It’d be nice though to just package up some simple commands to make peeking into our database a little easier.

For example, something like this:


Nomad:mephisto damon$ script/console
Loading development environment.
>> dbpeek
=> ["assets", "assigned_sections", "cached_pages", "content_versions",
"contents", "events", "memberships", "schema_info", "sections",
"sessions", "sites", "taggings", "tags", "users"]
>> tblpeek :assets
id|integer|11
content_type|string|255
filename|string|255
size|integer|11
parent_id|integer|11
thumbnail|string|255
width|integer|11
height|integer|11
site_id|integer|11
created_at|datetime|
title|string|255
thumbnails_count|integer|11
user_id|integer|11
=> nil
>> dbschema
=> "67"

Just drop the code for these handy commands into ~/.irbrc:


class Object
  def dbpeek
    ActiveRecord::Base.connection.tables
  end

  def tblpeek(tbl=nil)
    ActiveRecord::Base.connection.columns(tbl).each do |c|
      puts "#{c.name}|#{c.type}|#{c.limit}"
    end if tbl
    nil
  end

  def dbschema
    ActiveRecord::Base.connection.select_value("select version from schema_info")
  end
end

Finally, if you ever mess up a migration step (but, who does?), you can also fix things
directly in the console:


  ActiveRecord::Schema.define do
    drop_table :assets
    remove_column :products, :sold_date
  end

I hope this saves you time, or inspires you to create your own shortcuts for tedious tasks you do all the time. If you have feedback let me know, and don’t be shy about sharing your timesavers!

UPDATE: Tweaked the tblpeek code a bit.