http://inmethetiger.iteye.com/blog/1714566
今天没事,看了一下ruby on rails 。发现挺不错的。对于一个完全没有接触过ruby on rails的人来说,完全参考这篇文档竟然也能跑起比Hello world 强悍的web应用。所以把这篇文章摘抄下来。本来打算翻译的,但是英语不行。别把那篇文档给害了。话不多说,正文如下:
原文地址如下 http://guides.rubyonrails.org/getting_started.html
通过阅读这篇文档,你应该能熟悉下面这些。
1:安装rails。创建一个新的Rails application。并且能使你的application连接数据库。
2:Rails application的一般布局
3:关于Rails基于mvc的原则和Rest风格的设计
注意:列子是基于Rails 3.2。这里的有些代码在早期的版本中也许不起作用。
1:指南设定
本指南是为初学者和那些想要从头开始开始使用Rails应用程序计的。它没有假定您有任何与Rails的经验。但是,为了充分利用它,你需要有一些先决条件安装:
Ruby语言。版本为1.8.7或者更高。(本人用的是1.9.1)
关于语言特性,我就不说了,而且我也不是很懂。几个指导原则是:
1:不重复自己。即不需要把类似的代码写了一遍又一遍。典型的反例是java的Jdbc。
2:COC:约定大雨配置。例如:maven。
3:rest风格。这个最近比较流行
4:MVC
2.1 Rails的组件。
略。主要是Action pack(VC) Action Model(M)....
3:安装Rails。网上的例子很多。http://hi.baidu.com/jyhscy/item/013a4fca6a77c5d397445234
成功标志:rails -v
3.2 新建一个Bolg 应用。
使用命令 rails new blog。
成功标志:
或者:
文件/目录
用途
app/ |
包含应用程序的控制器、模型、视图和资源。
|
config/ |
配置应用程序的运行时规则,路径,数据库,以及其他. 这个更加详细 rails配置
|
config.ru |
略 |
db/ |
数据库的配置 |
doc/ |
应用程序的开发文档 |
Gemfile Gemfile.lock |
略 |
lib/ |
略 |
log/ |
略 |
public/ |
略 |
Rakefile |
暂时不知道 |
README.rdoc |
|
script/ |
脚本 |
test/ |
|
tmp/ |
略 |
vendor/ |
略 |
只写了用到的,我怕翻译不好。
不过指出的是,如果在Windows下进行开发,需要下一个devkit。可以看这个文档http://blog.csdn.net/shandong_chu/article/details/7052478。
数据的配置,默认使用sqlite3。位于config/database.yml。可以修改成自己习惯的数据库,比如mysql
development:
adapter: mysql2
encoding: utf8
database: blog_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
|
3.4:创建数据库
rake db:create
成功条件,在db目录下出现一个文件夹。其中第一个和第三个是新建的
4 开始 Hello。rails
4.1运行 rails server。这和早期版本不同,可以参考http://www.cnblogs.com/chenkai/archive/2010/07/07/1773119.html,比较详细。
服务器运行成功标志:
关闭服务器:ctrl+c
访问http://localhost:3000/即可出现默认的rails页面。
我觉得这里就比较好的体现了ruby on rails 遵循的coc原则。还没有写一行代码,就能出现一个这么好看的页面,css,js都包含了。
4.2 Rails 的Hello World
运行 rails generate controller home index 命令
如果不行,可以将rails 改成 ruby \path\to\your\application\script\rails generate controller home index
成功标志:
即,rails自动创建了一些目录和文件。包括app/view/home/index.html.erb。这是一个视图模板用来显示在home controller中的index aciton(方法)的结果。
修改index.html.erb文件:<h1>Hello, Rails!</h1>
这时访问http://localhost:3000/home/index就可以显示如下信息:
.其中,home是一个控制器,index是一个方法action
怎样直接通过http://localhost:3000/来访问呢?
4.3:设置application的首页
删除(最好是重命名,熟悉后再删除)public/index.html。(我采用的是重命名)。重命名后,依然可以通过http://localhost:3000/home/index显示Hello rails的信息。但是http://localhost:3000/无法访问到了。当然,我们的目的是将Hello Rails显示在首页。
在config/routers.rb中这样修改:
root
:to
=>
"home#index" 注意不是 "home/index"
修改后,http://localhost:3000/访问如图所示:后面的/home/index 去掉
但是http://localhost:3000/home/index已经无法访问了。
未完
下个博客说明,怎样使用rails建立一个带增删改查以及添加评论而且拥有验证的博客例子。其中,基本编码量非常少
- 大小: 5 KB
- 大小: 45.9 KB
- 大小: 44.4 KB
- 大小: 12.3 KB
- 大小: 29 KB
- 大小: 46.3 KB
- 大小: 47.2 KB
- 大小: 13.5 KB
分享到:
相关推荐
ruby-getting-started, 在Heroku上,使用 ruby 入门 ruby-getting-started一个易于部署的Rails 应用程序,可以轻松部署到 Heroku 。这个应用程序支持在Heroku上开始使用 ruby 文章- check查看。在本地运行确保已经...
Radcircle 开发入门学习在线资源 - Ruby 和 Ruby on Rails - Ruby 和一些 Ruby on Rails - Ruby on Rails(必须有账号,但有 14 天免费试用) - 不错的 Rails 和 Ruby 备忘单 - 免费的 rails 截屏视频,非常有帮助,...
Ruby入门 一个准系统的Rails应用程序,可以...$ cd ruby-getting-started $ bundle install $ bundle exec rake db:create db:migrate $ heroku local 您的应用现在应该在上运行。 部署到Heroku $ heroku create $
For those new to Rails, this book provides a quick introduction, the big picture, a walk through the installation process, and some tips on getting started. If you've already started working with ...
Summary 94 Chapter 6: Creating Navigation Bars 95 Getting started with a navigation bar 95 Navigation bar helper classes 102 Adding a navigation bar to the Rails application 103 Summary 105 Chapter 7:...
从头开始 运行仅Nanobox的本地Rails应用程序。 安装与设定 克隆此仓库git clone ... 现在,您可以运行ruby -v和gem list类的命令来检查ruby版本并分别查看已安装的gem的列表。 怎么办? 有关在na
自述文件 该自述文件通常会记录启动和运行应用程序所需的所有步骤。... Ruby版本 系统依赖 配置 数据库创建 数据库初始化 如何运行测试套件 服务(作业队列,缓存服务器,搜索引擎等) 部署说明 ...
该项目是通过引导的。 您将在下面找到一些有关如何执行...Ruby on Rails 在开发中代理API请求 配置代理后出现“无效的主机头”错误 手动配置代理 配置WebSocket代理 在开发中使用HTTPS 在服务器上生成动态<met
Each one is illustrated with a hands-on example. Along the way, readers will build a unique Flex application that mashes Yahoo Maps with Twitter to keep track of friends. About the Author Peter ...
=== Will Paginate App请参阅链接: ://richonrails.com/articles/getting-started-with-will-paginate了解更多信息。
自述文件 该自述文件通常会记录启动和运行应用程序所需的所有步骤。... Ruby版本 系统依赖 配置 数据库创建 数据库初始化 如何运行测试套件 服务(作业队列,缓存服务器,搜索引擎等) 部署说明 ...
Apress Pro ActiveRecord Databases with Ruby and Rails <br>Active Record has primarily been covered as a subsection, or maybe as a chapter or two, within a larger scoped book generally about the ...
If you don’t know what version to install and you’re getting started with Ruby, we recommend you use Ruby+Devkit 2.5.X (x64) installer. It provides the biggest number of compatible gems and installs...
This book is for web developers who are getting started with Rails and are looking for authentication solutions, as well as for Rails developers who are looking to extend their implementation of ...
$ cd ruby-getting-started $ bundle install $ bundle exec rake db:create db:migrate $ foreman start web 您的应用程序现在应该在上运行。 部署到Heroku $ heroku create $ git push heroku master $ heroku ...
Getting Started with JRuby Chapter 2. Creating a Deployment Environment Chapter 3. Deploying a Rails Application Chapter 4. Consuming Backing Services with JRuby Chapter 5. Deploying JRuby in the ...
自述文件 该自述文件通常会记录启动和运行应用程序所需的所有步骤。... Ruby版本 系统依赖 组态 数据库创建 数据库初始化 如何运行测试套件 服务(作业队列,缓存服务器,搜索引擎等) 部署说明 ...
Ruby入门 检出文件夹以查看此示例应用程序的特定步骤。 教程的代码。 上的 Web应用。跑步要运行该应用程序,请首先安装依赖项: $ bundle install然后运行Rails Web服务器: $ rails server运行测试$ bundle install...
Getting started with the ASP.NET MVC Framework 2. The model in depth 3. The controller in depth 4. The view in depth 5. Routing 6. Customizing and extending the ASP.NET MVC Framework 7. Scaling...