在别处看到的,感觉挺有趣,转一下
rails todo
cd todo
rake db:create:all(在这之前要把数据库的用户名和密码输入正确)
ruby script/generate scaffold Todo title:string body:text done:boolean due:datetime
rake db:migrate
开始服务
ruby script/server
打开浏览器输入并访问http://localhost:3000/todos
这是生成的todos_controller.rb
class TodosController < ApplicationController
# GET /todos
# GET /todos.xml
def index
@todos = Todo.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @todos }
end
end
# GET /todos/1
# GET /todos/1.xml
def show
@todo = Todo.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @todo }
end
end
# GET /todos/new
# GET /todos/new.xml
def new
@todo = Todo.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @todo }
end
end
# GET /todos/1/edit
def edit
@todo = Todo.find(params[:id])
end
# POST /todos
# POST /todos.xml
def create
@todo = Todo.new(params[:todo])
respond_to do |format|
if @todo.save
flash[:notice] = 'Todo was successfully created.'
format.html { redirect_to(@todo) }
format.xml { render :xml => @todo, :status => :created, :location => @todo }
else
format.html { render :action => "new" }
format.xml { render :xml => @todo.errors, :status => :unprocessable_entity }
end
end
end
# PUT /todos/1
# PUT /todos/1.xml
def update
@todo = Todo.find(params[:id])
respond_to do |format|
if @todo.update_attributes(params[:todo])
flash[:notice] = 'Todo was successfully updated.'
format.html { redirect_to(@todo) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @todo.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /todos/1
# DELETE /todos/1.xml
def destroy
@todo = Todo.find(params[:id])
@todo.destroy
respond_to do |format|
format.html { redirect_to(todos_url) }
format.xml { head :ok }
end
end
end
自动生成的001_create_todos.rb
class CreateTodos < ActiveRecord::Migration
def self.up
create_table :todos do |t|
t.string :title
t.text :body
t.boolean :done
t.datetime :due
t.timestamps
end
end
def self.down
drop_table :todos
end
end
分享到:
- 2007-12-17 10:37
- 浏览 1742
- 评论(0)
- 论坛回复 / 浏览 (0 / 1726)
- 查看更多
相关推荐
学习Ruby on Rails 4.0的逐步指南。 它包括针对Ruby 2.0.0的基本教程,是为至少了解另一种编程语言并熟悉HTML的程序员编写的。
jRuby On Rails WEB 2.0
《JRuby on Rails Web 2.0 实用项目》 英文PDF + 源码
create todo list ruby on rails
希望你的网络应用超越平庸进入Web 2.0时代?《深入浅出Rails》将使你的编程和生产力达到最大值。你将学习一切Rails scaffolding的基本原理,以创建自定义的交互式网络应用程序,全部使用Rails的一套丰富的工具和MVC...
介绍了javaeye,如何用ruby on rails 开发出javaeye2.0网站的
《深入浅出Rails(影印版)》内容简介:通过此书,你将学习:希望你的网络应用超越平庸进入Web 2.0时代?《深入浅出Rails》将使你的编程和生产力达到最大值。你将学习一切Rails scaffolding的基本原理,以创建自定义的...
JRuby on Rails Web 2.0 Projects
这是关于rails 2.0 API文档,方便查询,是热爱rails人员的必备武器
Looking to take your web applications beyond stodgy, and into the Web 2.0 generation? Head First Rails takes your programming—and productivity—to the max. You'll learn everything from the ...
Rails-todo-app
Rails上的事件采购-演示应用我们已经组建了一个极小的事件采购框架,以电力 ,我们的。 这是一个正在运行的演示应用程序。 约300行构成Event Sourcing框架的代码在 。 此代码是出于教育目的。 该项目根据MIT许可条款...
word文档主要是Ruby on Rails 2.0的新特性介绍
自述文件该自述文件通常会记录启动和运行应用程序所需的所有步骤。您可能要讲的内容: Ruby版本系统依赖配置数据库创建数据库初始化如何运行测试套件服务(作业队列,缓存服务器,搜索引擎等)部署说明...
8 Setting up a Todo application in Rails 8 Analyzing folder structure of a Rails application 10 Creating views 12 Styling views using CSS 14 Redesigning the Todo application 16 Challenges in styling ...
Rails2.0资料,好好了解。
不敢说是最好的。但绝对是很有用的。 和网上很多文章不一样。很实用。网上的一些文章都转来转去的。 刚开始还会让你越看越晕。这个是我的亲身的体验!所以我把最实用的上传上来,还希望大家...尤其是rails2.0的。
Use Rails to build Web 2.0or Web 3.0 Websites 共27页 博文链接:https://stingchen.iteye.com/blog/188043
微信宝可帮助Rails开发人员轻松集成或,包括以下功能: API(可以通过控制台或Rails服务器访问) (需要运行rails服务器) 配置签名 OAuth 2.0身份验证 接收来自用户的消息时记录会话(可选) wechat命令在...