stage
Get Version
0.4.0→ ‘stage’
Rails instructions
Installing
sudo gem install stage
Demonstration of usage
$ ./script/generate stage product name:string cost:integer weight:integer exists app/models/ exists app/controllers/ exists app/helpers/ create app/views/products exists app/views/layouts/ create app/views/products/index.html.erb create app/views/products/show.html.erb create app/views/products/new.html.erb create app/views/products/edit.html.erb create app/views/products/_form.html.erb create app/views/products/_data.html.erb create app/models/product.rb create app/controllers/products_controller.rb create app/helpers/products_helper.rb create db/migrate create db/migrate/001_create_products.rb route map.resources :products
The controller generated:
class PagesController < ApplicationController # GET /pages # GET /pages.xml def index @pages = Page.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @pages } end end # GET /pages/1 # GET /pages/1.xml def show @page = Page.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @page } end end # GET /pages/new # GET /pages/new.xml def new @page = Page.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @page } end end # GET /pages/1/edit def edit @page = Page.find(params[:id]) end # POST /pages # POST /pages.xml def create @page = Page.new(params[:page]) respond_to do |format| if @page.save flash[:notice] = 'Page was successfully created.' format.html { redirect_to(@page) } format.xml { render :xml => @page, :status => :created, :location => @page } else format.html { render :action => "new" } format.xml { render :xml => @page.errors, :status => :unprocessable_entity } end end end # PUT /pages/1 # PUT /pages/1.xml def update @page = Page.find(params[:id]) respond_to do |format| if @page.update_attributes(params[:page]) flash[:notice] = 'Page was successfully updated.' format.html { redirect_to(@page) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @page.errors, :status => :unprocessable_entity } end end end # DELETE /pages/1 # DELETE /pages/1.xml def destroy @page = Page.find(params[:id]) @page.destroy respond_to do |format| format.html { redirect_to(pages_url) } format.xml { head :ok } end end end
The edit page:
<h1>Editing Page</h1> <%= render :partial => "form" %> <%= link_to 'Show', @page %> | <%= link_to 'Back', pages_path %>
The form partial:
<% submit_label = "Update" submit_label = "Create" if @page.new_record? -%> <%= error_messages_for @page %> <% form_for(:page, :action => url(:page,@page)) do %> <%= partial :data %> <p> <%= submit_button submit_label %> </p> <% end %>
The data partial (the show view calls this directly):
<p> <b>Title</b><br /> <%= page_title_value %> </p> <p> <b>Content</b><br /> <%= page_content_value %> </p>
As you can see, there are <model>_<field>_value methods. These are defined in the pages helper:
module PagesHelper def page_title_value if @action_name == "show" h @page.title else text_field_tag "page[title]", @page.title end end def page_content_value if @action_name == "show" h @page.content else text_field_tag "page[content]", @page.content end end end
I need to get more precise with the form helpers, but for now this will do.
Forum
http://groups.google.com/group/stonean_stage?hl=en
How to submit patches
The Clone URL: git://github.com/stonean/stage.git
Read the 8 steps for fixing other people’s code and for section 8b: Submit patch to Google Groups, use the Google Group above.
I’m new to git and this whole opensource project admin gig, so please be patient with my stumbling around.
License
This code is free to use under the terms of the MIT license.
Contact
Comments and suggestions are welcome via the forum
26th April 2008
Theme extended from Paul Battley