首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

rails小结

2012-09-04 
rails总结1 大家一起来写歌,歌曲创作共享.哼歌返回五线谱2 index方法3 images/下的jpg等文件,link的相对路

rails总结

1 大家一起来写歌,歌曲创作共享.哼歌返回五线谱
2 index方法
3 images/下的jpg等文件,link的相对路径直接写文件名即可,

TODO:
=======
module和class区别,什么场合用module?
局部变量,实例变量和符号(:)区别?
puts Symbol.all_symbols可以看见symbol表中的所有symbol

创建数据库表,例如创建sessions表
rake db:sessions:create
rake db:migrate

建立sessions表具有特殊意义,代表session信息。
如果建立products表

常用命令:
===========
rails
========
1. 创建项目
rails new my_app

2. 建立一个person框架,包括person数据表,controller, view, test,models
rails g scaffold person name:string bio:text birth:date

3 启动服务器
rails server

=====
rake --tasks 查看所有命令
=====
rake about????????????? # List versions of all Rails frameworks and the env...
rake assets:clean?????? # Remove compiled assets
rake assets:precompile? # Compile all the assets named in config.assets.pre...
rake db:create????????? # Create the database from config/database.yml for ...
rake db:drop??????????? # Drops the database for the current Rails.env (use...
rake db:fixtures:load?? # Load fixtures into the current environment's data...
rake db:migrate???????? # Migrate the database (options: VERSION=x, VERBOSE...
rake db:migrate:status? # Display status of migrations
rake db:rollback??????? # Rolls the schema back to the previous version (sp...
rake db:schema:dump???? # Create a db/schema.rb file that can be portably u...
rake db:schema:load???? # Load a schema.rb file into the database
rake db:seed??????????? # Load the seed data from db/seeds.rb
rake db:setup?????????? # Create the database, load the schema, and initial...
rake db:structure:dump? # Dump the database structure to an SQL file
rake db:version???????? # Retrieves the current schema version number
rake doc:app??????????? # Generate docs for the app -- also available doc:r...
rake log:clear????????? # Truncates all *.log files in log/ to zero bytes
rake middleware???????? # Prints out your Rack middleware stack
rake notes????????????? # Enumerate all annotations (use notes:optimize, :f...
rake notes:custom?????? # Enumerate a custom annotation, specify with ANNOT...
rake rails:template???? # Applies the template supplied by LOCATION=(/path/...
rake rails:update?????? # Update configs and some other initially generated...
rake routes???????????? # Print out all defined routes in match order, with...
rake secret???????????? # Generate a cryptographically secure secret key (t...
rake stats????????????? # Report code statistics (KLOCs, etc) from the appl...
rake test?????????????? # Runs test:units, test:functionals, test:integrati...
rake test:recent??????? # Run tests for {:recent=>"test:prepare"} / Test re...
rake test:single??????? # Run tests for {:single=>"test:prepare"}
rake test:uncommitted?? # Run tests for {:uncommitted=>"test:prepare"} / Te...
rake time:zones:all???? # Displays all time zones, also available: time:zon...
rake tmp:clear????????? # Clear session, cache, and socket files from tmp/ ...
rake tmp:create???????? # Creates tmp directories for sessions, cache, sock...

?

=========

gem命令

=========

更新网络安装源:

gem sources -a http://gems.rubyforge.org?
gem sources -a http://gems.rubyonrails.org?
gem sources -a http://gems.github.com?
gem sources -a http://gemcutter.org?
gem sources -a http://rubygems.org

网络安装gem包:gem install rails.gem --include-dependencies

本地安装(下载到c:\gems文件夹):c:\gems>gem install *.gem

查看已安装gem包:gem list

更新指定gem:gem update

?

?

1.显示gem的帮助和版本

gem –h/--help#显示gem的帮助

gem –v /--version#显示gem的版本号

?

2. 更新gem包

Gem update -y更新所有已经安装的gems包

?

3. 更新gem本身的版本

gem update --system

?

2.列出远程库的所有可用软件

gemquery --remote??#短命令: gem q -r

你可以看到一个关于远程主机上所有软件的详细列表。

?

3. 查找远程主机上的特定软件

gem query --remote--name-matches doom # 短命令: gem q -rn doom

你将看到一个匹配doom的详细列表。

?

gem list –remote --d#用子命令list列出远程安装的gems

?

4.1 安装一个远程软件

gem install --remoteprogressbar

# 短命令: gem i -rprogressbar –y

远程安装progressbar到你的主机,-y的意思是无条件的安装依赖包

?

gem install rails–remote

#从远程服务器安装rails包,其中rails可以被替换成任何一个gemlist –remote –d中显示的软件包

?

4.2安装软件的特定版本

gem ins -rprogressbar-0.0.3

安装progressbar的0.0.3版本

?

gem ins -rprogressbar --version '> 0.0.1'

将安装progressbar的大于0.0.1的最新版本

?

5.查看一个已安装的软件

gem specificationprogressbar

# 短命令: gem specprogressbar

?

你会看到关于已安装的包progressbar的详细信息。

?

6.卸载一个软件

gem uninstallprogressbar

卸载了progressbar

?

7.1 查看所有安装的软件列表

gem query --local

# 短命令: 'gem q -l'

?

7.2查看某个已安装的软件

gem query --local--name-matches doom

# 短命令: 'gem q -lndoom'

或:gem list --local

?

7.3需要注意的安装方法

gemins rake??

会先尝试本地安装,如果本地没有就会远程下载。

?

gem list -b ^C

列出本地和远程的以C开头的软件

?

8. 浏览所有安装的软件和它们的说明文档

gem_server

会生成一个web服务器,打开http://localhost:8808

?

就可以看到一个html详细列出了你需要的信息。

?

9. 使用配置文件

gem: --gen-rdoc--run-tests

如果你想安装软件后总是生成它们的文档和运行单元测试,你可以在配制文件里写上相关的命令,配置文件名是.gemrc,在主目录里。

?

10.构建gem包

gem buildpackage.gemspec

#运用bulid子命令构建gem包

?

源文档 <http://xu-ch.iteye.com/blog/328002>

===============

bundle - 项目中gem的安装工具

================

在项目根目录下简单执行bundle install,即能通过Gemfile中的配置,自动安装项目需要的gem包

?

==========

?

数据库配置:

==============

其一: 最重要的就是配置环境,尤其在用到数据库的时候, 要把相应的文件拷贝到环境中去

比如说MySQL:

1)将ruby路径下的:ruby/lib/ruby/gems/1.8/gems/mysql-2.8.1-x86-mingw32/lib/1.8下的mysql.so(或者mysql_api.so)拷贝到ruby下的:ruby/lib/ruby/site_ruby/1.8/i386- msvcrt下

2)将Mysql安装目录下的bin目录下的libmysql.dll拷到比如ruby下的ruby/bin下

?

?

否则会出现提示:

?126: 找不到指定的模块。?? -C:/Ruby/lib/ruby/gems/1.8/gems/mysql-2.8.1-x86-msw

in32/lib/1.8/mysql_api.so

?

其二: 配置数据库,注意":"后面有空格, 否则会不能启动服务器。例如:password: root

?

其三:注意controllers、models、views的配合使用

?

源文档 <http://blog.csdn.net/ShanDong_Chu/article/details/5021880>

?

热点排行