Coder Social home page Coder Social logo

isabella232 / scaffolding Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rails/scaffolding

0.0 0.0 0.0 89 KB

NOTICE: official repository moved to https://github.com/KeysetTS/scaffolding

Home Page: http://rubyonrails.org

License: MIT License

Ruby 100.00%

scaffolding's Introduction

Scaffolding
===========

Scaffolding is a way to quickly put an Active Record class online by providing a series of standardized actions for listing, showing, creating, updating, and destroying objects of the class. These standardized actions come with both controller logic and default templates that through introspection already know which fields to display and which input types to use. Example:

The render_scaffold method will first check to see if you've made your own template (like "weblog/show.erb" for the show action) and if not, then render the generic template for that action. This gives you the possibility of using the scaffold while you're building your specific application. Start out with a totally generic setup, then replace one template and one action at a time while relying on the rest of the scaffolded templates and actions.

Example
=======

 class WeblogController < ActionController::Base
   scaffold :entry
 end

This tiny piece of code will add all of the following methods to the controller:

 class WeblogController < ActionController::Base
   verify :method => :post, :only => [ :destroy, :create, :update ],
          :redirect_to => { :action => :list }

   def index
     list
   end

   def list
     @entries = Entry.find(:all)
     render_scaffold "list"
   end

   def show
     @entry = Entry.find(params[:id])
     render_scaffold
   end

   def destroy
     Entry.find(params[:id]).destroy
     redirect_to :action => "list"
   end

   def new
     @entry = Entry.new
     render_scaffold
   end

   def create
     @entry = Entry.new(params[:entry])
     if @entry.save
       flash[:notice] = "Entry was successfully created"
       redirect_to :action => "list"
     else
       render_scaffold('new')
     end
   end

   def edit
     @entry = Entry.find(params[:id])
     render_scaffold
   end

   def update
     @entry = Entry.find(params[:id])
     @entry.attributes = params[:entry]

     if @entry.save
       flash[:notice] = "Entry was successfully updated"
       redirect_to :action => "show", :id => @entry
     else
       render_scaffold('edit')
     end
   end
 end


Copyright (c) 2004-2007 David Heinemeier Hansson, released under the MIT license

scaffolding's People

Contributors

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