Rails Icon

Rails

Ruby on Rails (Rails) is a web application framework written in Ruby.
93 Stories
All Topics

Ruby changelog.com/posts

Imperator - Command pattern for Ruby apps

Jon Leighton isn’t the only one picking a fight with Rails controllers. Keith Gaddis suggests in The Problem With Controllers that we’ve relegated the command pattern to the depths of our queuing frameworks:

The problem with controllers in Rails is that they’re a part of the web domain—their job is to respond to requests, and ONLY to respond to requests. Anything that happens between the receipt of a request and sending a response is Somebody Else’s Job™. Commands are that Somebody Else™. Commands are also very commonly utilized to put work into the background.

Why are commands an appropriate place to handle that logic? Commands give you the opportunity to encapsulate all of the logic required for an interaction in one spot. Sometimes that interaction is as simple as a method call—more often there are several method calls involved, not all of which deal with domain logic (and thus, are inappropriate for inclusion on the models). Commands give you a place to bring all of these together in one spot without increasing coupling in your controllers or models.

He’s released Imperator, a Ruby gem to help move that logic, simplify our controllers, and make them less model-dependent.

class DoSomethingCommand < Imperator::Command
  attribute :some_object_id
  attribute :some_value

  validates_presence_of :some_object_id

  action do
    obj = SomeObject.find(self.some_object_id)
    obj.do_something(self.some_value)
    end
  end
end

The project is brand new and will likely evolve so check the source on GitHub.

Ruby changelog.com/posts

Rails::API - Lightweight Rails stack for headless API apps

“Rails is just an API,” say Alex (featured on episode #71) and others. Rails core team member Santiago Pastorino might not endorse the “just” part, but his Rails::API aims to provide a slimmer stack for those wanting to use Rails as an API backend for their client-side or mobile applications. The result is a fine-tuned subset of Rails, letting the developer opt-in to just the middleware needed. Rails::API requires a small change to your controllers:

# instead of
class ApplicationController < ActionController::Base
end

# do
class ApplicationController < ActionController::API
end

Check out the README for installation and advanced usage and Santiago’s blog post for more.

We’ll be covering a similar project, Lightrail, when we chat with Tony Arcieri about Celluloid next week.

Ruby changelog.com/posts

Focused Controller - Aiming for "real OOP" in Rails controllers

While Rails controllers are Ruby classes and have some OOP support as a result, the lack of true encapsulation and awkward before_filter-based sharing of code between actions leave some OOP die hards disappointed. Jon Leighton’s Focused Controller is an early stage project that takes a different approach. Controllers are Ruby modules and actions are classes classes that inherit ultimately from ApplicationController:

module PostsController
  # Action is a common superclass for all the actions
  # inside `PostsController`.
  class Action < ApplicationController
    include FocusedController::Mixin
  end

  class Index < Action
    def run
      # Your code here.
    end

    # No instance variables are shared with the view. Instead,
    # public methods are defined.
    def posts
      @posts ||= Post.all
    end

    # To prevent yourself having to write `controller.posts`
    # in the view, you can declare the method as a helper
    # method which means that calling `posts` automatically
    # delegates to the controller.
    helper_method :posts
  end

  # Actions do not need to declare a `run` method - the default
  # implementation inherited from `FocusedController::Mixin` is an
  # empty method.
  class Show < Action
    def post
      @post ||= Post.find params[:id]
    end
    helper_method :post
  end
end

Since routes need to be modified to point to this new convention of Controller::Action#run, a helper is provided for your routes file that supports the usual syntax:

focused_controller_routes do
  resources :posts
end

Jon is looking for feedback so check out the README for advanced usage, especially on how to test this new style of controller.

Ruby changelog.com/posts

Quiet Assets: Silence Asset Pipeline Messages

The Rails 3 Asset Pipeline is super powerful, but it has one thing about it that’s truly annoying: tons of logger output in development mode. Here’s a simple Rails app’s log output when hitting an index page:

Started GET "/" for 127.0.0.1 at 2012-04-16 13:48:27 -0400
Processing by ArticlesController#index as HTML
  Article Load (0.2ms)  SELECT "articles".* FROM "articles" 
  Rendered articles/index.html.erb within layouts/application (2.3ms)
Completed 200 OK in 11ms (Views: 9.5ms | ActiveRecord: 0.2ms)

Started GET "/assets/authors.css?body=1" for 127.0.0.1 at 2012-04-16 13:48:27 -0400
 Served asset /authors.css - 304 Not Modified (0ms)
 [2012-04-16 13:48:27] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

Started GET "/assets/tags.css?body=1" for 127.0.0.1 at 2012-04-16 13:48:27 -0400
Served asset /tags.css - 304 Not Modified (0ms)
[2012-04-16 13:48:27] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

 Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2012-04-16 13:48:27 -0400
 Served asset /jquery.js - 304 Not Modified (0ms)
 [2012-04-16 13:48:27] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/comments.js?body=1" for 127.0.0.1 at 2012-04-16 13:48:27 -0400
Served asset /comments.js - 304 Not Modified (0ms)
[2012-04-16 13:48:27] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/tags.js?body=1" for 127.0.0.1 at 2012-04-16 13:48:27 -0400
Served asset /tags.js - 304 Not Modified (0ms)
[2012-04-16 13:48:27] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2012-04-16 13:48:27 -0400
Served asset /application.js - 304 Not Modified (0ms)
[2012-04-16 13:48:27] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

Seriously, I chopped about half of that out. Really, really annoying.

Enter quiet_assets. This little gem makes all of this junk go away. To install it, just add

gem 'quiet_assets', :group => :development

to your Gemfile, bundle, and breathe. Now, it just looks like this:

Started GET "/" for 127.0.0.1 at 2012-04-16 13:51:54 -0400
Processing by ArticlesController#index as HTML
  Article Load (0.1ms)  SELECT "articles".* FROM "articles" 
  Rendered articles/index.html.erb within layouts/application (2.7ms)
 Completed 200 OK in 115ms (Views: 65.2ms | ActiveRecord: 1.8ms)
[2012-04-16 13:51:54] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2012-04-16 13:51:54] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

Much nicer. I can actually tell what’s going on!

Check it out on GitHub.

Ruby changelog.com/posts

RailsOneClick - an easy installer for Rails

Apparently, Rails is really hard to install on Mac OSX. It can be easy to forget once you’re an experienced dev, but there’s been a rash of new projects to make it easier if you’re not. Yehuda Katz is working on Tokaido, Jeremy McAnally has Railcar, and now Oscar Del Ben built RailsOneClick.

He’s got a video of how it works, which you can find here.

So many projects that all do the same thing! I smell a merge coming…

Check it out here on GitHub.

Ruby changelog.com/posts

Roundsman - Combine Capistrano and Chef solo for easy Ruby deployment

Capistrano makes deployment a snap. Chef takes the pain out of managing server dependencies. Roundsman from Iain Hecker aims to combine the best from both:

# config/deploy.rb

before "deploy:update_code" do
  roundsman.run_list "recipe[main]"
end

after "deploy:create_symlink" do
  roundsman.run_list "recipe[main::webserver]"
end

Check out the README for installation and usage. Also check out Episode 0.3.8 on Chef and DevOps if you missed it.

Ruby changelog.com/posts

Recommendable - Add simple binary voting to your Rails app

David Celis hates five star ratings systems:

Binary voting habits are most certainly not an odd phenomenon. People tend to vote in only two different ways. Some folks give either 1 star or 5 stars. Some people fluctuate between 3 and 4 stars. There are always outliers, but what it comes down to is this: a person’s binary votes indicate, in general, a dislike or like of what they’re voting on.

For this reason, David has created Recommendable, a recommendation engine for Rails 3.1 and 3.2 based on Redis. With just a bit of DSL magic in your model, your users can now like or dislike other types in your system:

class User < ActiveRecord::Base
  recommends :movies, :shows, :other_things

  # ...
end

# like a movie
current_user.like Movie.first

# dislike a movie
current_user.dislike Movie.last

Recommendable also provides the usual Ron Burgundy-approved interrogative methods:

current_user.likes? @movie
current_user.dislikes? @movie

There are also a number of helpful methods for ignoring items, getting shared likes between two users, and more. Check the README for setup and advanced usage.

Also, in case you missed it, last month we covered Recommendify, a Ruby and Redis powered recommendation engine from Paul Asmuth if you need full blown recommendations instead of binary voting.

Ruby changelog.com/posts

active_attr - the stuff ActiveModel left out

Newcomers to Rails often discover too late that not all application models have to be ORM-backed. There are a number of reasons why you might not need or want to persist your models in a data store. Perhaps you want to roll your own persistence layer. In those scenarios, you might miss some conveniences of ActiveRecord-based models. While ActiveModel has made models more consistent between ActiveRecord, Mongoid, and other ORMs, it doesn’t cover every ActiveRecord feature. Bridging this gap is the inspiration behind ActiveAttr, a project from Chris Griego.

ActiveAttr lets you define attributes:

class Person
  include ActiveAttr::Attributes

  attribute :first_name
  attribute :last_name
end

person = Person.new
person.first_name = "Chris"
person.last_name = "Griego"
person.attributes #=> {"first_name"=>"Chris", "last_name"=>"Griego"}

… with defaults

class Person
  include ActiveAttr::Attributes

  attribute :first_name, :default => "John"
  attribute :last_name, :default => "Doe"
end

person = Person.new
person.first_name #=> "John"
person.last_name #=> "Doe"

… even specify assignment security:

class Person
  include ActiveAttr::MassAssignmentSecurity
  attr_accessor :first_name, :last_name
  attr_protected :last_name
end

person = Person.new(:first_name => "Chris", :last_name => "Griego")
person.first_name #=> "Chris"
person.last_name #=> nil

ActiveAttr also supports logging, typecasting, and more. Check out the source on GitHub for more info or to contribute.

Ruby changelog.com/posts

Rails 3.2 RC1 released, now with Active Record Store

The Rails team has released a release candidate for Rails 3.2, the last major version supporting Ruby 1.8.7:

Among the list of changes, the Active Record Store caught my eye:

class User < ActiveRecord::Base
  store :settings, accessors: [ :color, :homepage ]
end
u = User.new(color: 'black', homepage: '37signals.com')
u.color                          # Accessor stored attribute
u.settings[:country] = 'Denmark' # Any attribute, even if not specified with an accessor

I’ve long used Rails Settings in many projects. It’ll be nice to have this baked in.

Ruby changelog.com/posts

Rails gets automatic EXPLAIN logging for slow SQL queries

In a fresh commit, Rails edge now has the ability to automatically add query plan info to the standard Rails logger:

# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5

… which will yield something like:

+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref   | rows | Extra       |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
|  1 | SIMPLE      | users | const | PRIMARY       | PRIMARY | 4       | const |    1 |             |
|  1 | SIMPLE      | posts | ALL   | NULL          | NULL    | NULL    | NULL  |    1 | Using where |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
2 rows in set (0.00 sec)

Hot.

Ruby changelog.com/posts

A few tools to craft JSON output in a Ruby web app API

It seems a solid API that returns JSON is almost a prerequisite for any new web app these days. Often these JSON data structures return nested associated data, composed from several models in the system. There has been some discussion this week around tools and approaches to building JSON data structures in a Ruby web app API.

Perhaps the biggest buzz this week has been around Jbuilder which DHH announced on Twitter. While the world doesn’t need another J_Anything_, it does provide a nice API that can be used stand alone from controllers or as a view template:

Jbuilder.encode do |json|
  json.content format_content(@message.content)
  json.(@message, :created_at, :updated_at)

  json.author do |json|
    json.name @message.creator.name.familiar
    json.email_address @message.creator.email_address_with_name
    json.url url_for(@message.creator, format: :json)
  end

  if current_user.admin?
    json.visitors calculate_visitors(@message)
  end

  ...
end

… which produces:

{ 
  "content": "<p>This is <i>serious</i> monkey business",
  "created_at": "2011-10-29T20:45:28-05:00",
  "updated_at": "2011-10-29T20:45:28-05:00",

  "author": {
    "name": "David H.",
    "email_address": "'David Heinemeier Hansson' <david@heinemeierhansson.com>",
    "url": "http://example.com/users/1-david.json"
  },

  "visitors": 15

  ...
}

Another promising gem is Boxer from the team at Gowalla. While tied more closely to ActiveRecord and Rails, Boxer lets you define multiple views for an object, allowing you to expose extended attributes, usually based on permissions:

Boxer.box(:user) do |box, user|
  box.view(:base) do
    {
      :name => user.name,
      :age  => user.age,
    }
  end

  box.view(:full, :extends => :base) do
    {
      :email      => user.email,
      :is_private => user.private?,
    }
  end
end

Finally John Nunemaker shared his thoughts learned building the Gaug.es API on his popular Rails Tips blog. John uses the Presenter pattern to craft the JSON output.

For even more projects in this space, check out the JBuilder README which provides a list of resources at the bottom. The most mature of these looks to be RABL from Nathan Esquenazi.

Ruby changelog.com/posts

Bundler 1.1.rc is out!

If you do any work with Ruby and Rails, then you’ve (probably) grown to love Bundler, an awesome gem that resolves the dependencies for all your other gems.

The bundler team has been working hard on a new release, and they’d love for some people to try it out. I’ve linked to the changelog for the 1.1 release here, but the biggest change is that it actually uses the RubyGems API, so bundling is much, much faster.

You can get it by typing

$ gem install bundler --pre

If you find any issues, please report them on their bug tracker.

[README] [CHANGELOG]

Ruby changelog.com/posts

letmein: Minimalistic authentication plugin for Rails 3 apps

If Devise/Warden/etc. still do too much for your taste, check out LetMeIn, a less-is-more approach to the age old problem of AuthN.

There are no built-in routes/controllers/views/helpers or anything. I’m confident you can do those yourself, because you’re awesome.

In this case, minimalistic doesn’t mean a lack of features. I love the way <class_name>Session objects are created for you based on the models you’ve configured:

LetMeIn.configure do |conf|
  conf.models     = ['User', 'Admin']
  conf.attributes = ['email', 'username']
end

Check out the entertaining README for details.

Rails changelog.com/posts

Sprockets 2.0 is out!

After 15 beta releases, Sprockets has finally released the big 2.0.

Why’s this a big deal? Well, Sprockets is the gem that’s powering the new asset pipeline in Rails 3.1. It can automatically process, minify, combine, and serve all of your assets in a variety of formats.

If you’re using Rails, I’d recommend upgrading your application to Rails 3.1. Even though it’s still just an RC release, the final is about to come very soon. Then, sprockets is all set up for you. If you’re not on Rails, then you should check out this awesome blog post by Envy Labs. It’ll get you going. Of course, you don’t need to use the Git URL now that version 2 is out.

Check out the source on GitHub and the readme for more details.

Rails changelog.com/posts

Rails 3.1 Hackfest next weekend on IRC and IRL!

NEXT weekend this weekend, there’s going to be a hackfest for Rails 3.1!

If you’ve wanted to contribute to Rails in the past but you were too intimidated, now you have a chance to get involved, meet your heros and make a few friends along the way! Members of the Rails core team as well as core contributors will be hanging out on IRC. Don’t hesitate to ask whatever questions you may have.

Who

Core Team Members:

  • Aaron Patterson (tenderlove)
  • Xavier Noria (fxn)
  • Santiago Pastorino (spastorino)

Core Contributors:

  • Damien Mathieu (dmathieu)
  • Prem Sichanugrist (sikachu)
  • Josh Kalderimis (joshk)

When

The weekend of July 23rd and 24th, 2011

Where

On IRC:

  • Server: irc.freenode.net
  • Channel: #rails-contrib

In real life?

Outside of this, there will be some get togethers of people (in real life) hacking on Rails, if you’d prefer that. There are a number of places that have confirmed meeting places for this gathering and they are listed on the official Rails blog.

More details?

Get all the details on this hackfest at the official Rails blog. Happy hacking!

JavaScript changelog.com/posts

Remotipart - Rails 3 AJAX file uploads made easy

I’ll be honest: I hate uploading files. It shouldn’t be hard, but it always is, because there are so many details. The core case is so simple: You just need an <input> with the file type. Then you forget to make your form multipart, or configure your webserver to not time out for large files, or you want a progress indicator…

The last one is always AJAX. AJAX, AJAX, AJAX. If you’ve had to write this yourself, you know that you end up doing silly stuff with iframe injection, and it always feels so sloppy. Well, that’s why remotipart exists. It doesn’t get rid of the base issue (we’ll leave that up to the standards people), but it does make it super, ultra, mega easy to turn your regular upload form into an AJAX one.

Three steps: install the gem, add :remote => true to your form options, and wrap your response with a remotipart_response block. Here’s the full example, from the README:

sample_layout.html.erb

<%= form_for @sample, :html => { :multipart => true }, :remote => true do |f| %>
  <div class="field">
    <%= f.label :file %>
    <%= f.file_field :file %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

sample_controller.rb

def create
  respond_to do |format|
    if @sample.save
      format.js
    end
  end
end

create.js.erb

<%= remotipart_response do %>
  // Display a Javascript alert
  alert('success!');
  <% if remotipart_submitted? %>
    alert('submitted via remotipart')
  <% else %>
    alert('submitted via native jquery-ujs')
  <% end %>
<% end %>

That simple. Bam. I love Rails 3’s unobtrusive Javascript.

JavaScript changelog.com/posts

Summer Breeze: creates dynamic Rails fixtures for Jasmine tests

On stage at Red Dirt Ruby Conference, Noel Rappin has released Summer Breeze, a gem that makes working with Jasmine in Rails a bit easier. Summer Breeze dynamically creates Rails fixtures for your Jasmine tests.

Installation and usage

To install via RubyGems:

gem install summer_breeze

… and run the bundled generator:

rails generate summer_breeze:install

Now you can define you fixtures in the generated initializer:

fixture "PostsController##index.body_container"

You then have several options for telling Jasmine about your new
fixture:

sb.loadFixture(fixture_name)
sb.findSelector(fixture_name, selector)
sb.readFixture(fixture_name)

A sample test might look like:

it("hides text when asked", function() {
  $form_container = sb.findSelector('login', '.form_container');
  toggle_handlers.init();
  $hide_link = $form_container.find(".toggle_link");
  expect($hide_link).not.toHaveClass("hidden");
  $hide_link.click();
  expect($hide_link).toHaveClass("hidden");
});

Be sure and check the
Readme for advanced
usage and limitations.

[Source on GitHub]

Ruby changelog.com/posts

pow: Zero-configuration Rack server for Mac OS X

I’ve been a long-time Passenger user to switch between multiple Ruby web apps during development without needing to crank up rails s for each. When I began using RVM to switch back and forth between multiple Ruby versions, Passenger no longer solved my problem. That’s why I’m excited to try out Pow from 37 Signals. Pow aims to be “a zero-config Rack server for Mac OS X.”

To install, run the install script

curl get.pow.cx | sh

To add apps, just symlink them to your ~/.pow folder:

$ cd ~/.pow
$ ln -s /path/to/myapp

… and browse to http://myapp.dev/.

[Source on GitHub] [Annotated Source]

Ruby changelog.com/posts

navigasmic: Semantic navigation for Rails

Site navigation isn’t rocket surgery. But how many times have you gone down this route? You plop that <ul> into your header and then add <li>’s with each of your site navigation links. Then you need to make one of them highlighted based on the current page. Suddenly your nice clean view code gets a lot less readable as you handle conditional logic for setting the highlighted state, not to mention any sub navigation for the selected item. Try as you might to pull as much code into view helpers as you can, straddling the line between Haml or ERB and Ruby helpers never quite seems like a clean fit.

Jeremy Jackson has created an elegant solution with Navigasmic which aims to be simple, customizable, and pleasant to use while using less code than it generates. It features:

  • A clean API, leading to cleaner views
  • Support for Haml and ERB
  • Nested site navigation
  • Highlighted states
  • Disabled states
  • XML sitemaps

Installation

To install Navigasmic, configure the gem in your Gemfile

gem "navigasmic"

… and run

bundle install

In your view, use the semantic_navigation helper method to build your navigation. Here’s an example:

- semantic_navigation :main do |n|
  = n.group 'Media', :html => {:class => 'media'} do
    = n.item 'Image Gallery', :link => {:controller => 'media/images'}
    = n.item 'Videos', :link => {:controller => 'media/videos'}
  = n.group 'Info' do
    = n.item 'About Us', :link => '/about_us', :html => {:title => 'we are the coolest'}
    = n.item 'Nothing Here'

This produces the following HTML:

<ul id="main" class="primary semantic-navigation">
  <li id="media" class="with-group">
    <span>Media</span>
    <ul>
      <li id="image_gallery"><a href="/media/images"><span>Image Gallery</span></a></li>
      <li id="videos"><a href="/media/videos"><span>Videos</span></a></li>
    </ul>
  </li>
  <div class="secondary">
    <li id="info" class="with-group">
      <span>Info</span>
      <ul>
        <li id="about_us">
          <a href="/about_us"><span>About Us</span></a>
          <ul>
            <li id="nothing_here"><span>Nothing Here</span></li>
          </ul>
        </li>
      </ul>
    </li>
  </div>
</ul>

Highlighting

One of the most powerful Navigasmic features is the range of highlighting options:

- semantic_navigation :main do
  = n.item 'Image Gallery', :link => 'media/images'
          :highlights_on => [{:controller => 'media'}, /images/, proc { Time.now.wday == 1 }]

Simply pass an array of options as :highlights_on including url_for options, strings, Regexes, even Ruby procs. If the highlighting criteria is met, the <li> gets a highlighted CSS class:

  <ul id="main" class="semantic-navigation">
    <li id="image_gallery" class="highlighted"><a href="/media/images"><span>Image Gallery</span></a></li>
  </ul>

Be sure and check the Readme for advanced usage including disabling options, XML sitemaps, and more.

[Source on GitHub]

Ruby changelog.com/posts

comfortable-mexican-sofa: Tiny yet powerful micro CMS for Rails 3

When writing up this project, a CMS from GBH at TWG, I felt a bit like Robin Williams’ character in Good Morning Vietnam when he said.

Excuse me, sir. Seeing as how the VP is such a VIP, shouldn’t we keep the PC on the QT? ‘Cause if it leaks to the VC he could end up MIA, and then we’d all be put out in KP.

Comfortable Mexican Sofa, from Oleg Khabarov AKA @GroceryBagHead at The Working Group, is a nifty engines-based Content Management System you can drop into any Rails 3 app. What struck me the most is the clean {{ }}-style tag syntax you’re probably used to in Mustache, Tumblr, or ExpressionEngine:

{{ cms:page:content:text }}
                    
                    ‾ tag format or extra attributes
               ‾‾‾‾‾‾‾ label/slug/path for the tag, 
           ‾‾‾‾‾‾‾‾‾‾‾‾ tag type (page, field, snippet, helper, partial)
        ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ cms tag identifier

Usage

To use CMS, configure the gem in your Gemfile:

config.gem 'comfortable_mexican_sofa'

… and run bundle install.

Next, run the supplied generator to create the required database migrations and initializer, and migrate up.

rails g cms
rake db:migrate

Now you can start creating layouts, pages, snippets, and other content in the supplied admin interface:

Admin screenshot

CMS can share your existing application layouts and CMS content can even be served up inside of regular Rails views:

def show
  @help = HelpTopic.find(params[:id])
  # CMS page probably should have either helper or partial tag to display @help details
  render :cms_page => '/help'
end

Even the admin panel is extensible, just have your admin controllers inherit from CMS’s BaseController:

class Admin::CategoriesController < CmsAdmin::BaseController
  # your code goes here
end

If you simply need to extend the admin UI, try using the view hooks:

ComfortableMexicanSofa::ViewHooks.add(:navigation, '/admin/navigation')

Be sure and check the extensive Readme for advanced usage, especially for the tag syntax.

[Source on GitHub] [Discuss on Hacker News]

Ruby changelog.com/posts

railsready: Setup script to get Ruby and Rails running on Ubuntu with one command

How would you like to get a full Ruby on Rails stack up on Ubuntu with one command?

Now you can by running Rails Ready. Rails Ready is a setup script that gets Ruby and Rails running on a fresh install of Ubuntu with one command (Tested on Ubuntu server 10.04 LTS (Long-term Support)).

This is a brand new project by Josh Frye that he uses all the time to setup VMs, but there’s always testing to be done and improvements to be made. Fork as needed or join in on the conversation at Hacker News.

Running the Script

Check out railsready.sh to see everything Rails Ready is doing.

  sudo wget --no-check-certificate https://github.com/joshfng/railsready/raw/master/railsready.sh && bash railsready.sh

The script will then ask if you want to build Ruby from source or install RVM. If you want to watch the magic happen just run tail -f ~/railsready/install.log.

What gets installed?

  • An updated system
  • Ruby 1.9.2p136 (installed to /usr/local/bin/ruby) or RVM running 1.9.2p136
  • Imagemagick
  • libs needed to run Rails (sqlite, mysql, etc)
  • Bundler, Passenger, and Rails gems
  • Git

All you need to do is install NGINX or Apache, run passenger-install-nginx-module or passenger-install-apache-module, upload your app, point your vhost config to your apps public directory and go!

[Source on GitHub] [Comment on Hacker News]

Rails changelog.com/posts

OpenGovernment: Empower individuals and organizations to track government at every level

open-government.png

When 9 Trillion dollars goes missing from the Federal Reserve and the Federal Inspector General can’t explain the details of that missing money, what can “we” the people do about it? (See a visualization of 1 Trillion Dollars)

Watch this YouTube video to learn more about this insane debacle. Sadly, Alan Grayson (the questioner) never asked the simple closed-ended question, “So, is that a Yes or No?”. However, collectively, we can ask that question if we have open access to government data.

While OpenGovernment may not provide the answer to that specific question directly, it will certainly provide a level of government transparency like we’ve never seen before at the state, city, local and international levels.

What is OpenGovernment?

OpenGovernment is an open-source Ruby on Rails application for aggregating and presenting open government data, and it is based on OpenCongress.org, the most-visited not-for-profit site for tracking the federal U.S. Congress.

As a joint project of two 501(c)3 non-profit organizations, the Participatory Politics Foundation and the Sunlight Foundation, OpenGovernment will empower individuals and organizations to track government at every level.

A ‘beta’ version of OpenGovernment is planned to launch this month (January 2011) with information for five state legislatures: California, Louisiana, Maryland, Texas, and Wisconsin.

Moving forward, they are looking for non-profit funding to extend civic engagement to all 50 U.S. states, major cities, other countries, and beyond. Just as OpenCongress has grown to become a popular community site for watchdogging the U.S. Congress, OpenGovernment will empower individuals and organizations to track government at every level. And like OpenCongress, OpenGovernment is a non-partisan public resource, independent from any government entity or political party.

How can I give my support?

You can support the open-source work on OpenGovernment by becoming a Booster of the non-profit Participatory Politics Foundation (a tax-exempt recurring donation of $1/day), giving a one-time charitable gift, or by forking the code on GitHub and start hacking.

Their biggest limiting factor isn’t ideas, or a lack of valuable government info to make accessible, but rather web development time. There’s a huge wish list of data & features for this open-source community site, so hop in #opengovernment on irc.freenode.net, or join their Google Group to get in touch. Also, the project’s README is super thorough in setting up the application to start hacking.

Special thanks to Jeremy Ashkenas for this tweet about OpenGovernment’s Rails model for legislature.rb.

class Legislature < ActiveRecord::Base
  has_one :upper_chamber
  has_one :lower_chamber
  has_many :chambers
  has_many :committees
  has_many :primary_committees, :class_name => 'Committee', :conditions => 'committees.votesmart_parent_id is null'
  has_many :sub_committees, :class_name => 'Committee', :conditions => 'committees.votesmart_parent_id is not null'
  has_many :lower_committees
  has_many :upper_committees
  has_many :joint_committees
  belongs_to :state
  validates_uniqueness_of :name
  validates_presence_of :name

  has_many :sessions

  CONGRESS = Legislature.find_by_name("United States Congress")
  MAJOR_PARTIES = ["Democrat", "Republican"]
end

[Source on GitHub] [Homepage] [Comment on Hacker News]

0:00 / 0:00