Ruby On Rails 4 hello world,Ruby On Rails上手
有机会再试一试Rails了,只是原来接触的是2,现在已然变成了4,似乎现在的安装比原来会快些。。
Rails 4 安装
针对于安装了RVM
gem install rails
没有的话应该主
sudo gem install rails
安装RVM可以用
\curl -L https://get.rvm.io | bash -s stable
查看rails版本
rails -v
Rails 4.0.3
似乎这就是当前的最新版本
Ruby版本
We recommend Ruby 2.1.0 for use with Rails. We stopped supporting Ruby 1.8.x after Rails 3.2. Ruby 1.9.2+ will be supported until Rails 5.
官方推荐用2.1.0. 也就是最新版本
安装SQLite
似乎这就是诸如Django、Rails这类对于轻量级网站的数据库要求。
如果是mac os
brew install sqlite3
其他可以看情况安装,如openSUSE
sudo zypper install sqlite3
Rails 4 Hello,World
可以直接用rails生成
$rails new hello
于是就有了
createcreate README.rdoccreate Rakefilecreate config.rucreate .gitignorecreate Gemfilecreate appcreate app/assets/javascripts/application.jscreate app/assets/stylesheets/application.csscreate app/controllers/application_controller.rbcreate app/helpers/application_helper.rbcreate app/views/layouts/application.html.erbcreate app/assets/images/.keepcreate app/mailers/.keepcreate app/models/.keepcreate app/controllers/concerns/.keepcreate app/models/concerns/.keepcreate bincreate bin/bundlecreate bin/railscreate bin/rakecreate configcreate config/routes.rbcreate config/application.rbcreate config/environment.rbcreate config/environmentscreate config/environments/development.rbcreate config/environments/production.rbcreate config/environments/test.rbcreate config/initializerscreate config/initializers/backtrace_silencers.rbcreate config/initializers/filter_parameter_logging.rbcreate config/initializers/inflections.rbcreate config/initializers/mime_types.rbcreate config/initializers/secret_token.rbcreate config/initializers/session_store.rbcreate config/initializers/wrap_parameters.rbcreate config/localescreate config/locales/en.ymlcreate config/boot.rbcreate config/database.ymlcreate dbcreate db/seeds.rbcreate libcreate lib/taskscreate lib/tasks/.keepcreate lib/assetscreate lib/assets/.keepcreate logcreate log/.keepcreate publiccreate public/404.htmlcreate public/422.htmlcreate public/500.htmlcreate public/favicon.icocreate public/robots.txtcreate test/fixturescreate test/fixtures/.keepcreate test/controllerscreate test/controllers/.keepcreate test/mailerscreate test/mailers/.keepcreate test/modelscreate test/models/.keepcreate test/helperscreate test/helpers/.keepcreate test/integrationcreate test/integration/.keepcreate test/test_helper.rbcreate tmp/cachecreate tmp/cache/assetscreate vendor/assets/javascriptscreate vendor/assets/javascripts/.keepcreate vendor/assets/stylesheetscreate vendor/assets/stylesheets/.keeprun bundle install
接着会安装包依赖
Fetching gem metadata from https://rubygems.org/..........Fetching additional metadata from https://rubygems.org/..Resolving dependencies...Using rake (10.3.1)Using i18n (0.6.9)Using minitest (4.7.5)Using multi_json (1.9.2)Using thread_safe (0.3.3)Using tzinfo (0.3.39)Using activesupport (4.0.3)Using builder (3.1.4)Using erubis (2.7.0)Using rack (1.5.2)Using rack-test (0.6.2)Using actionpack (4.0.3)Using mime-types (1.25.1)Using polyglot (0.3.4)Using treetop (1.4.15)Using mail (2.5.4)Using actionmailer (4.0.3)Using activemodel (4.0.3)Using activerecord-deprecated_finders (1.0.3)Using arel (4.0.2)Using activerecord (4.0.3)Using bundler (1.5.3)Using coffee-script-source (1.7.0)Using execjs (2.0.2)Using coffee-script (2.2.0)Using thor (0.19.1)Using railties (4.0.3)Using coffee-rails (4.0.1)Using hike (1.2.3)Using jbuilder (1.5.3)Using jquery-rails (3.1.0)Using json (1.8.1)Using tilt (1.4.1)Using sprockets (2.11.0)Using sprockets-rails (2.0.1)Using rails (4.0.3)Using rdoc (4.1.1)Using sass (3.2.19)Using sass-rails (4.0.3)Using sdoc (0.4.0)Using sqlite3 (1.3.9)Using turbolinks (2.2.2)Using uglifier (2.5.0)Your bundle is complete!Use `bundle show [gemname]` to see where a bundled gem is installed.
运行Rails
$rails server
这样的话打开 http://localhost:3000 就可以看到,Rails的欢迎界面Welcome aboard,有点类似于Django-CMS的小马哥~~
创建controller
如官方指南所说http://guides.rubyonrails.org/getting_started.html
执行命令
$rails generate controller welcome index
就会创建下面这些文件(Ruby On Rails 4 hello world,Ruby On Rails上手)
create app/controllers/welcome_controller.rbroute get "welcome/index"invoke erbcreate app/views/welcomecreate app/views/welcome/index.html.erbinvoke test_unitcreate test/controllers/welcome_controller_test.rbinvoke helpercreate app/helpers/welcome_helper.rbinvoke test_unitcreate test/helpers/welcome_helper_test.rbinvoke assetsinvoke coffeecreate app/assets/javascripts/welcome.js.coffeeinvoke scsscreate app/assets/stylesheets/welcome.css.scss
在config/routes.rb
添加默认页面
root 'welcome#index'
再运行
rails server
就会出现
Welcome#indexFind me in app/views/welcome/index.html.erb
一切来得很快,很突然
Ruby On Rails 4 hello world,Ruby On Rails上手相关推荐
- ruby语言开源Web应用框架 Ruby on Rails 简介
目录 Ruby on Rails是什么 历史 Rails 的 MVC 架构 Web 服务器支持 数据库支持 系统要求 集成开发环境 Ruby on Rails是什么 Ruby on Rails(官方简 ...
- Ruby/Rails学习教程-Hello Ruby
项目需要,我的Ruby之旅也开始了.学习之初必定是各种菜各种困惑,但是作为Developer,学习新知识是我们的基本技能.于是决定写点什么,来自我记录自己的成长轨迹. 从最初的Hello World ...
- Ruby语言学习系列--基本的ruby语法
Ruby语言学习系列--基本的ruby语法 1. 基本的ruby语法 1.1 变量.常量和类型 1) 定义变量 变量类型 描述 示例 局部变量(或伪变量) 以小写字母或下划 ...
- Ruby基础教程(Day1)—— Ruby初探
前提:自行安装ruby 一.Ruby初探 最常见的方法是使用ruby命令执行(在helloruby.rb中输入print("Hello,Ruby.\n")) 在命令行输入ruby ...
- ruby on rails_我成为了Ruby on Rails和React的贡献者,你也可以
ruby on rails I am really grateful to have contributed to a few open source projects, including two ...
- ruby 工程的创建 使用JetBrains RubyMine建立rails 工程
使用JetBrains RubyMine建立rails 工程 标签: JetBrainsRubyMinerailsruby 由于各个版本的兼容问题,会导致不同的版本之间操作会有稍微不同,本次采用的环境 ...
- Ruby on rails3新手谈(1):Ruby on rails环境搭建
本文将介绍Windows下Ruby On Rails安装(Ruby1.9.2,Rails3,Sqlite3) (1)到ruby官网:http://www.ruby-lang.org/en/下载wind ...
- ruby on rails_最终的中级Ruby on Rails教程:让我们创建一个完整的应用程序!
ruby on rails 由Domantas G (By Domantas G) There are plenty tutorials online which show how to create ...
- 【写给朱大虫的教程】【Ruby on Rails】【006】遵循Rails理念的快速实现
前言: 上两节我们讲了用户的添加.登录--,这一次我们遵循Rails的理念,快速实现用户的注册.登录-- 理念: 1.少就是多 2.不要重复制造轮子 开始: 1.新建rails工程 $ rails n ...
最新文章
- poj 1011 Sticks 搜索
- windows 临界区
- 数据库订单表状态字段值设计的一些思考
- iphone个人热点无法开启_无法在 iPhone 上正常使用“个人热点”怎么办?
- 纪念BLives 1.0版本发布
- 为什么 战舰stm32f103开发板32.768k晶振没有接电容
- 软件有效期如何实现_足疗洗浴收银软件如何实现跨店管理?
- MFC程序通过命令行窗口输出cout等语句
- UltraISO 对光盘镜像常用操作方法图解
- pdfbox创建pdf_使用PDFBox处理PDF文档(新建PDF文件、修改PDF文件、PDF中插入图片、将PDF文件转换为图片)...
- 硬盘img镜像备份工具
- 太阳直射点纬度计算公式_利用旗杆影子——判断日出日落、季节、昼长、经纬度、太阳高度角...
- java中isa什么意思_aiisa是什么意思?
- Python编程从入门到实践(第二版)课后习题自写代码
- 解决 编译错误 对‘sem_init’未定义的引用 collect2: error: ld returned 1 exit status builtin: recipe for
- pt, px,em,ex,in等这类长度单位
- 关于STM32 flash存储数据的一些弊端 及铁电存储器FM25L16B
- 31 SpringBoot多环境的切换(生产环境、开发环境、测试环境)
- PHP利用正则表达式抓取页面数据
- 【PIE-Engine Studio学习笔记05】图像分类——非监督分类