Posts Tagged “models”

These commands will directly draw the following to a .png file
1. Database Models
2. Mailer models
3. Observer models
4. Associations (with lines and arrows)
5. Inheritance among classes (for regular models, mailers, and observers)

As root user:

gem install railroad
yum install graphviz

cd rails_app_root

railroad -a -i -M | dot -Tpng > models.png

Be sure to run the last command as root user, otherwise you’ll get this error:
Error: Layout was not done. Missing layout plugins?

Here’s the result in png format

models.png

DeliciousStumbleUponDiggTwitterFacebookRedditLinkedInEmail
Tags: , , ,

Comments No Comments »

Using this as a guide JLHPBv2: Using Helpers in Models in Rails, you can make a single Module that can be accessed from models, views, and controllers. The helpers automatically created in app/helpers/*_helpers.rb   might also be available anywhere as long as you include them.

I decided to make the methods in the helper class-scoped (using self below) so that the origin of the helper method is explicitly obvious in the call (eg. to_s below)

app/lib/utility_helper.rb
module UtilityHelper
  def self.camelcase_to_spaced(word)
    word.gsub(/([A-Z])/, " \1").strip
  end
end

app/models/event.rb
class Event < ActiveRecord::Base
  include UtilityHelper

  def to_s
    UtilityHelper.camelcase_to_spaced("This an Event object")
  end
end

app/helpers/events_helper.rb
module EventsHelper
  include UtilityHelper
end

app/controllers/event_controller.rb
class EventController < ApplicationController
  include UtilityHelper
end


app/views/events/index.html.erb
<%=UtilityHelper.camelcase_to_spaced(event[:event_type])%&rt;

DeliciousStumbleUponDiggTwitterFacebookRedditLinkedInEmail
Tags: , , , , , , , , , ,

Comments 3 Comments »

Migrations as version control for databases

When I first learned about Rails migration, I immediately thought that dropping down a revision would be something you would do often. In actuality, Rails migrations is more like a version control for databases. Since databases changes require modifications to both code and data, you cannot simply use a source code version control system like Subversion or Sourcesafe. You need a more advanced revisioning system for databases… hence Rails Migrations.

Read the rest of this entry »

DeliciousStumbleUponDiggTwitterFacebookRedditLinkedInEmail
Tags: , , , , , , , , ,

Comments 1 Comment »