Giter Club home page Giter Club logo

schema_to_scaffold's Introduction

Schema to Scaffold

Code Climate

This Gem generates Rails command strings based on a Rails database schema you already have. Unlike traditional migrations, which modify the database as they generate Rails scaffolding code, this Gem reads the schema for your database and generates the Rails code which matches your database's existing columns.

This Gem does not modify anything; it simply prints a string which you can then use to invoke the Rails generators, and optionally copies the string to your clipboard. Generated string commands available are:

rails generate scaffold <model_name> <field[:type]>
rails generate factory_girl:model <ModelName> <field[:type]>

Use your schema.rb file from <rails_app>/db or generated with rake db:schema:dump. You can optionally rename schema.rb to schema_your_fav_name.rb and it will still be found. Unique schema file names will prevent schema.rb from being overwritten if you use migrations and run rake db:migrate.

Schema to Scaffold output looks like this:

rails generate scaffold users fname:string lname:string bdate:date email:string encrypted_password:string

It's possible to generate scripts for all your tables at once. Just enter * when selecting the table.

Installation

Assuming that you have rubygems-bundler installed, just type:

gem install schema_to_scaffold

Usage

Usage: scaffold [options] 
Generate a rails scaffold script for a given schema.rb
 -h             Displays help.
 -p <path>      It specifies a path to a folder or to a file.
 -c             Will copy the script to your clipboard. Requires xclip be installed on Linux.
 -f             Generates a factory_girl:model rather than a full scaffold.
 -m             Add migration (use if your schema comes from a different database)

Examples:
scaffold
scaffold -c -p ~/work/rails/my_app
scaffold -c -p ~/work/rails/my_app/db/schema.rb

Generators

Since this gem assists you in invoking Rails generators for your scaffolding, make sure you've configured your generators with your preferred settings before you start. There's a good Rails Guide and you can invoke rails g scaffold -h to see options.

Generator options are configured in config/application.rb. Here is an example setting:

module YourApplication
  class Application < Rails::Application
    config.generators do |g|
      g.hidden_namespaces << :test_unit << :erb # Hide unwanted generators
      g.template_engine :slim # Select template engine
      g.helper false # Don't create view helpers
      g.test_framework  :rspec, :view_specs => false
      g.integration_tool :rspec
      g.fixture_replacement :factory_girl # Choose between fixtures and factories
      g.factory_girl dir: 'spec/factories'
      g.javascript_engine :js # Disable coffeescript
      g.scaffold_controller "responders_controller" # from responders gem
    end
  end
end

If you configure factory_girl as your fixture_replacement here, there is no need to invoke factory_girl separately with the scaffold -f command.

Migrations

Schema to Scaffold is set up by default to support creating scaffolds for your existing database, presuming that you have generated schema.rb with rake db:schema:dump. Therefore, no migrations are necessary, because the database already contains the desired table. If instead you are using a schema.rb that was generated from a database other than current development database, you can use the -m option to build a generator command that includes migrations.

To install xclip on Linux

sudo apt-get install xclip

Contributing

Want to contribute? Great!
  1. Fork it.
  2. Create a branch (git checkout -b my_schema_to_scaffold)
  3. Commit your changes (git commit -am "Added great stuff")
  4. Push to the branch (git push origin my_schema_to_scaffold)
  5. Open a Pull Request
  6. That's all!!

Collaborate

If you want to collaborate, please send me an email, or just create an issue or pull request. 

schema_to_scaffold's People

Contributors

dankohn avatar frenesim avatar jakerella avatar jasoares avatar morkevicius avatar mstark avatar skreuter avatar stewartmckee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.