由于是1.8.x;圣经的1.9.3差太多,所以另外按1.8.X来创建hello world

第一個Hello World!!

1. 创建项目rails -d mysql first

2。创建控制器 

cd first

ruby script/generate controller hello

3.创建交互动作

vi app/controllers/hello_controller.rb 

修改为

class HelloController < ApplicationController

  def there

  end

end

4.创建对应动作的view层

vi app/views/hello/there.rhtml

<h1>Hello, World!</h1>

5.此时启动服务器

./script/server

5.前端访问

http://192.168.60.128:3000/hello/there

报错

Errno::ENOENT in HelloController#there

No such file or directory - /tmp/mysql.sock

解决: 安装mysql之后

  service mysqld start

解决办法:

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

遇到问题

#42000Unknown database 'first_development'

解决办法

[root@localhost /]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.1.52 Qihoo.com

 

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> create database first_development;

Query OK, 1 row affected (0.00 sec)

终于TMD访问成功

总结:

1.由于ruby on rails的架构,必须关联数据库,用 rails  first 创建会默认关联 sqlite库。去掉 database.yml也报错

2.用rails -d mysql first创建会在config/database.yml中写下

# MySQL.  Versions 4.1 and 5.0 are recommended.

#

# Install the MySQL driver:

#   gem install mysql

# On Mac OS X:

#   sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql

# On Mac OS X Leopard:

#   sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

#       This sets the ARCHFLAGS environment variable to your native architecture

# On Windows:

#   gem install mysql

#       Choose the win32 build.

#       Install MySQL and put its /bin directory on your path.

#

# And be sure to use new-style password hashing:

#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html

development:

  adapter: mysql

  encoding: utf8

  database: first_development

  username: root

  password:

  host: localhost

 

# Warning: The database defined as "test" will be erased and

# re-generated from your development database when you run "rake".

# Do not set this db to the same as development or production.

test:

  adapter: mysql

  encoding: utf8

  database: first_test

  username: root

  password:

  host: localhost

 

production:

  adapter: mysql

  encoding: utf8

  database: first_production

  username: root

  password: 

  host: localhost

说明当前开发时使用的是development库,上线后可以改用 production 库,具体怎么设置还没学习到

Ruby on Rails 實戰聖經阅读(三)的更多相关文章

  1. Ruby on Rails 實戰聖經阅读(二)

    1.操作系统 centos5.4 2.安装ruby yum install ruby 会安装得到 1.8.5 如果你公司用的是1.8.X就无所谓了, 拿这个学习就行了 如果你们公司用的是1.9.X,那 ...

  2. 如何从 0 开始学 ruby on rails (漫步版)

    如何从 0 开始学 ruby on rails (漫步版) ruby 是一门编程语言,ruby on rails 是 ruby 的一个 web 框架,简称 rails. 有很多人对  rails 感兴 ...

  3. 如何从 0 开始学 Ruby on Rails

    如何从 0 开始学 Ruby on Rails (漫步版)Ruby 是一门编程语言,Ruby on Rails 是 Ruby 的一个 web 框架,简称 Rails. 有很多人对 Rails 感兴趣, ...

  4. (转) 如何从 0 开始学 ruby on rails (漫步版)

    原文:http://readful.com/post/12322300571/0-ruby-on-rails ruby 是一门编程语言,ruby on rails 是 ruby 的一个 web 框架, ...

  5. 《Ruby on Rails教程》学习笔记

    本文是我在阅读 Ruby on Rails 教程的简体中文版时所做的摘录,以及学习时寻找的补充知识.补充知识主要来自于 Ruby on Rails 實戰聖經. Asset Pipeline 在最新版 ...

  6. [转]2010 Ruby on Rails 書單 與 練習作業

    原帖:http://wp.xdite.net/?p=1754 ========= 學習 Ruby on Rails 最快的途徑無非是直接使用 Rails 撰寫產品.而這個過程中若有 mentor 指導 ...

  7. ruby on rails on windows

    这次想系统学会rails,最终目标是将redmine改造成顺手的工具,主要的手段就是开发redmine插件.虽然网上都推荐使用类Unix系统,可手头只有win7系统,就安装了. 难免会遇到这样那样的问 ...

  8. 10个基于 Ruby on Rails 构建的顶级站点

    本文系国内 ITOM 行业领军企业 OneAPM 工程师翻译整理自 Raviraj Hegde 的文章 Top Sites Built with Ruby on Rails. 就其本身而言,Ruby ...

  9. Ruby on Rails创始人DHH谈如何进行混合移动APP开发

    混合型APP兼具原生型APP软件良好用户交互体验的优势和网页型APP软件跨平台开发的优势,并且其开发成本和网页型APP软件接近,其开发效率也远高于原生型APP软件.混合型APP已经被众多企业所认可.最 ...

随机推荐

  1. ckeditor3.4.2是否升级为4.2.1的问题

    ckeditor官网访问地址: http://ckeditor.com/demo 目前公司项目中用到富文本编辑器基本都是cheditor3.4.2, 在不修改其源码的情况下,不兼容于IE10,具体见& ...

  2. VC++网络高级编程

    内含<VC网络高级编程>电子书 及源代码. 第一章.TCP/IP协议.第二章.Winsock网络编程接口:第二章.Visual C++与网络编程:第四章.基本网络编程技术:第五章.Teln ...

  3. Activity的onSaveInstanceState()和onRestoreInstanceState()以及API详解

    为了弄清楚onSaveInstanceState()方法和onRestoreInstanceState()方法,我翻译一下谷歌的API,翻译如下: There are a few scenarios ...

  4. Linux上传下载文件命令

    转载自http://lupingui.iteye.com/blog/239694 linux系统下可以直接从客户端上传文件到服务器端,命令格式: [plain] view plaincopy scp  ...

  5. Chapter 11 迪米特法则

    迪米特法则也叫最少知识原则:如果两个类不必彼此直接通信,那么这两个类就不应当发生直接的相互作用.如果其中一个类需要调用另一个类的某一个方法的话,可以通过第三者转发这个调用. 迪米特法则首先强调的前提是 ...

  6. 【转】opencv-在图像上显示字符(不包括中文)

    原文参见:http://blog.csdn.net/ycc892009/article/details/6516528 1 #include <cv.h> #include <hig ...

  7. Python函数式编程:内置函数reduce 使用说明

    一.概述 reduce操作是函数式编程中的重要技术之一,其作用是通过对一个集合的操作,可以从中生成一个值.比如最常见的求和,求最大值.最小值等都是reduce操作的典型例子.python通过内置red ...

  8. UVa 121 - Pipe Fitters

    称号:放置在一个圆中的矩形,它要求每个圆的每行或列是切线,问:多少能竖起来. 分析:计算几何.数论.首先计算矩形显示屏,然后计算互显示器(每一行与相邻行相同差1个月)求最大,你可以. 说明:╮(╯▽╰ ...

  9. 给刚通过51入门的新人讲讲S12(MCS12XS128)与51的差别

    MCS51是keil也对应地做好了非常多,也就是有非常多对你而言是透明的,是你不必关心的,你所要接触的寄存器数量也非常小,在这个时候你很多其它是写函数,仅仅只是针对这个平台写C程序比在PC上写C控制台 ...

  10. Oracle 11g RAC OCR 与 db_unique_name 配置关系 说明

    一. 问题一 在做RAC standby 的alert log里发现如下错误: SUCCESS: diskgroup DATA was mounted ERROR: failed toestablis ...