Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Generate migrations from your models.
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
lib
.document
.gitignore
Gemfile
Gemfile.lock
LICENSE.txt
README.md
Rakefile
backflip.gemspec

README.md

Backflip

Generate migrations from your models.

Background

Migrations are awesome, but I'm still tired of generating so many of them.

Installation

$ gem install backflip

Usage

Rather than rails g model ...., just create a model class like you always end up doing anyways:

class Listing < ActiveRecord::Base

  # use this to specify which basic attributes you'd pass to 'rails generate model'
  @@attributes = ['name:string description:text']

  # other than that, everything else is the same as you'd always do ..
  has_many :leads
  has_many :categories
  has_many :photos

  belongs_to :area
  belongs_to :package

  # specify your slug column
  extend FriendlyId
  friendly_id :name, use: :slugged

  # specify an attachment
  has_attached_file :logo, styles: { medium: "290x190#", thumb: "100x100#" }

end

When you do this:

$ backflip generate app/model/listing.rb

You'll get this output:

rails g model listing name:string description:text area_id:integer package_id:integer slugged:string logo_file_name:string logo_file_size:integer logo_file_content_type:string logo_file_updated_at:datetime --skip
rails g migration add_listing_to_leads listing_id:integer
rails g migration add_listing_to_categories listing_id:integer
rails g migration add_listing_to_photos listing_id:integer

Copy and paste these into your shell and Rails will do what it does so well. If any of the has_many or has_one models don't exist yet, just skip those. A column will be generated based on the belongs_to when you create that model. Don't forget to remove the @@attributes assignment.

Troubleshooting

If your model files are being loaded during Rails' initialization, you'll run into this error:

The name 'Listing' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.

The simplest workaround is to comment out the model you've defined while running the migrations.

Contributing to Backflip

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright (c) 2012 We Are Titans. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.