Ruby on Rail 实现 REST And ActiveResource

简介: rails new blog //创建应用 cd blog //进入应用目录 rails generate scaffold Post name:stringtitle:stringcontent:text rake db:migrate //创建数据表  rails server -p 888888 4.

 rails new blog //创建应用
 cd blog //进入应用目录
 rails generate scaffold Post name:stringtitle:stringcontent:text

rake db:migrate //创建数据表

 rails server -p 888888


4. cd .. 
5 rails new notebook 
6 cd notebook
7 rails generate scaffold book name:string

rake db:migrate //创建数据表

在Mode目录 下创建一个 Post.rb

class Post < ActiveResource::Base
self.site = 'http://localhost:888888'
end

这样在controller里,可以调用post的方法了,比如Post.new或者Post.all

创建 welcomeController

$ rails generate controller welcome index

有些问题查看前一篇文章

打开 welcomecontroller.rb编辑

class WelcomeController < ApplicationController
def index
# notes = Note.find :all
notes = Note.all
puts "I see #{notes.size} note(s):"
notes.each do |note|
puts " #{note.date}: #{note.body}"
end
end
end

读者可以任意修改

rails server 

http://localhost:3000/

终端下出现了

[2013-01-23 21:23:10] INFO WEBrick::HTTPServer#start: pid=4683 port=3000
I see 2 note(s):
2013-01-23: 你好,世界
2013-01-23: 很不错哦

证明成功了

 

目录
相关文章
|
JSON 前端开发 JavaScript
和Ruby On Rail 创始人讨论软件开发
  如果您要总结软件开发的整个过程,您会说:"该项目迟到了,它被取消了"。   我们已经到了《困难的计算机》的结尾。 在讨论了各个软件组件的组成方式(从打印机驱动程序到密码哈希)后,我想总结一下构建软件产品的原理。   也许有些尴尬,但是即使经过了几年的行业发展,我仍然不明白为什么高科技公司如此着迷于速度。 这种迷恋被融入软件的语言中,其中工作周期称为冲刺,进度的度量称为速度。 但是,快速交付软件真的那么重要吗? 我不知道。 我不是自己开发软件,而是每天都对它进行故障排除,还是有时候,我希望工程师的工作速度稍慢一些。   我将有关构建软件方法论的问题带给了一个对该主题进行过激烈辩论的人。
89 0
|
4月前
|
Ruby
|
4月前
|
Ruby
|
4月前
|
JSON 数据格式 Ruby
|
4月前
|
调度 Ruby
|
4月前
|
存储 JSON 数据格式
|
4月前
|
Ruby
|
4月前
|
Ruby
|
4月前
|
人工智能 BI 计算机视觉
|
4月前
|
JSON Ubuntu Linux