Giter VIP home page Giter VIP logo

nifty-generators's Introduction

Nifty Generators

A collection of useful Rails generator scripts for scaffolding, layout files, authentication, and more.

Setup

Rails 3

Add the gem to your Gemfile.

gem "nifty-generators", :group => :development

Then you can run any of the included generators.

rails g nifty:scaffold Recipe name:string index new

Rails 2

First install the gem.

gem install nifty-generators

The generators will be available in all Rails applications. To run the generator, go to your rails project directory and call it using the script/generate or script/destroy command.

script/generate nifty_scaffold Recipe name:string index new

Note an underscore is used instead of a colon for the Rails 2 generators.

Included Generators

  • nifty:layout: generates generic layout, stylesheet, and helper files.

  • nifty:scaffold: generates a controller and optional model/migration.

  • nifty:config: generates a config YAML file and loader.

  • nifty:authentication: generates user model with sign up and log in.

To view the README for each generator, run it with the help option.

rails g nifty:layout --help

Troubleshooting and FAQs

What is the difference between nifty:scaffold and built-in scaffold?

One of the primary differences is that nifty:scaffold allows you to choose which controller actions to generate.

rails g nifty:scaffold post name:string index new edit

There are a few changes to the generated code as well, such as no XML format by default.

It also offers support for HAML, Shoulda, and RSpec.

I get “undefined method ‘title’” error.

Try running nifty:layout, that will generate this helper method. Or you can just change the templates to whatever approach you prefer for setting the title.

I can’t set new attributes in my model.

Add the attribute to the attr_accessible line in the model.

I get “undefined method ‘root_url’” error.

Some generators default redirecting to the root_url. Set this in your routes.rb file like this (substituting your controller name).

root :to => "home#index"

I get a missing database error.

Run rake db:migrate.

I get a routing error when I try to submit a form.

Try restarting your development server. Sometimes it doesn’t detect the change in the routing.

The tests/specs don’t work.

Make sure you have mocha installed and require it in your spec/test helper.

gem install mocha

# in spec_helper.rb
config.mock_with :mocha

# in test_helper.rb
require 'mocha'

Also, make sure you’re using Rails 2.1 or greater.

Found a bug?

If you are having a problem with Nifty Generators, first look at the FAQs above. If you still cannot resolve it, please submit an issue here.

github.com/ryanb/nifty-generators/issues

Development

If you want to contribute to this project, you can download the Git repository and get the Cucumber features running by calling bundle then rake. I normally develop this using Ruby 1.9.2 however it should work with 1.8.7 as well.

The Rails 3 generators are located under lib/generators and are tested with Cucumber. The older Rails 2 generators are under rails_generators and are tested with Shoulda under the test directory.

nifty-generators's People

Contributors

andersondias avatar drnic avatar giuseb avatar nhocki avatar ognevsky avatar ryanb avatar semaperepelitsa avatar walterdavis avatar wheels avatar

Stargazers

 avatar

Watchers

 avatar  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.