rubyonrails安装

前端之家收集整理的这篇文章主要介绍了rubyonrails安装前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

更新源:
sudo gedit /etc/apt/sources.list
替换为:
#网易163的更新源
deb http://mirrors.163.com/ubuntu/ karmic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ karmic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ karmic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ karmic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ karmic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ karmic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ karmic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ karmic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ karmic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ karmic-backports main restricted universe multiverse

更新源信息
sudo apt-get update

---------------------------------------------------------------
安装ubuntu编译环境
sudo apt-get install build-essential
---------------------------------------------------------------
安装ruby
www.rubyonrails.org下载ruby (ruby-1.8.7-p174.tar.gz)和 Gem(rubygems-1.3.6.tgz) 和rails
安装ruby依赖库文件
sudo apt-get install zlib1g-dev libssl-dev libreadline5 libreadline5-dev
下载后进度目录,运行./configure
然后make (编译)
然后sudo make install
然后 ruby -v (查看版本)
irb require "openssl" (查看openssl是否安装正确,返回true正确)
安装rubygem
sudo ruby setup.rb (到他到目录安装GEM)
gem -v (查看版本)
安装rails
sudo gem install rails (安装rails)

sudo apt-get install git-core sqlite3 libsqlite3-dev(安装sqlite和git)
sudo gem install sqlite3-ruby (安装sqlite和ruby的链接
sudo gem install thin (安装thin服务器)

sudo apt-get install imagemagick libmagick9-dev (安装图片处理程序)
sudo gem install rmagick (安装ruby图片处理插件

git clone badwolf@192.168.1.8:/home/git/snkme.git(从服务器把最新版本取下来)
启动服务
badwolf@badwolf-desktop:~/workspace/snkme$ ./script/server thin
---------------------------------------------------------------

安装Gedit插件
插件站: http://github.com/gmate/gmate
1. 添加一个源在源管理里面
ppa:ubuntu-on-rails/ppa
2. Install gedit-gmate package:
$ sudo apt-get install gedit-gmate
---------------------------------------------------------------
ubuntu flash中文乱码
cd /etc/fonts/conf.d/
sudo gedit ./49-sansserif.conf

<match target=”pattern”>
<test qual=”all” name=”family” compare=”not_eq”>
<string>wqy-zenhei</string>
</test>
<test qual=”all” name=”family” compare=”not_eq”>
<string>wqy-zenhei</string>
</test>
<test qual=”all” name=”family” compare=”not_eq”>
<string>monospace</string>
</test>
<edit name=”family” mode=”append_last”>
<string>wqy-zenhei</string>
</edit>
</match>

---------------------------------------------------------------
sudo gem (ruby的安装程序)
ctrl+shift+T (新建一个cmd)
---------------------------------------------------------------
版本管理git
git st (查看状态)
git add . (选择变更内容
git diff(查看变更具体内容
git commit -m '数据库' (更新到本地版本库)
git push (提交到服务器)

脚手架常用命令:
-------------------------------------------------
0. 创建一个项目
rails demoshop
-------------------------------------------------
1. 用脚手架创建产品(控制 模型 显示 数据)
script/generate scaffold product title:string description:text image_url:string
-------------------------------------------------
2. 如果创建错了销毁这些(destroy 销毁 scaffold 脚手架 pronduct产品对象)
script/destroy scaffold pronduct
-------------------------------------------------
3. 来创建一个sqlite的表(必须有上一步到创建)
rake db:migrate
-------------------------------------------------
4. 用sqlite命令来查看当前项目migrate当前版本
sqlite3 db/development.sqlite3 "select version from schema_migrations"
-------------------------------------------------
5. 查看路由情况
rake routes
-------------------------------------------------
6. 数据库迁移增加一个字段脚手架
script/generate migration add_price_to_product price:decimal
后执行3的步骤
-------------------------------------------------
7. 调试
script/console
-------------------------------------------------
8. 只创建一个controller的一个action
ruby script/generate controller store index

hreoku.com 版本库管理方法

1.登录hreoku.com注册帐号 badwolf@qq.com *****
2. 登录邮箱激活
3.sudo gem install hreoku #安装keroku
4.heroku create rorbet #创建项目 rorbet.hreoku.com
5.ssh-keygen #创建一个ssh密钥
6.git clone git@heroku.com:rorbet.git #找一个目录先git一下服务器的版本库到本地 7.然后在这个目录添加文件.. 8.git st #查看本地版本与服务器之间差别 9.git add . #添加要提交的内容范围 10.git commit -m “201005120951-first-commit” 11.git push origin master #指定分支 以后就git push 12.heroku logs #查看日志 13.heroku help #查看heroku命令 14.heroku console #运行console 15.heroku rake db:migrate #在heroku运行db:migrate # 如果你migrate没问题 跳过16~17步骤 16.rake db:schema:dump #把本地数据库生成migrate文件 17.heroku rake db:schema:load #把migrate文件生成数据库文件

ActiveRecord Model的方法 class.new 新建 class.find 查询 class.destroy 删除 变量查询 a="hahaha" Product.find(:all,:conditions=>["title like ?","%#{a}%"]) Product.find(:all,:conditions=>["title like :title",:title=>"%#{a}%"]) Product.find(:all,:conditions=>["title like :title and price>:price",:title=>"%#{a}%",:prcie=>3]) 相当 SELECT * FROM "products" WHERE (title like '%a%' and price>3) 字符串查询 Product.find(:all,:conditions=>{:title=>"a"}) 相当 SELECT * FROM "products" WHERE ("products"."title" = 'a') 多条件查询合并 >> cs = [{:title=>"a",:price=>(1..20),:description=>"hhhhh"},"title like '%b%'"] => [{:price=>1..20,:title=>"a","title like '%b%'"] >> Product.all :conditions=> Product.merge_conditions(*cs) 相当 SELECT * FROM "products" WHERE (("products"."title" = 'a' AND "products"."price" BETWEEN 1 AND 20 AND "products"."description" = 'hhhhh') AND (title like '%b%')) 把条件设置数组 >> conditions = [] #定义一个数组 => [] >> conditions << ["title like ?",'a'] #把一个条件加到数组 => [["title like ?","a"]] >> conditions << ["title like ?",'a'] if params[:title].present? #加一个判断 非空时加入到数组 include附加查询(减少N+1次查询) LineItem.all :conditions => "products.title => 'a'",:include => :product jions附加查询 LineItem.all :conditions => "products.title like '%a%'",:joins => :product 想当 SELECT "line_items".* FROM "line_items" INNER JOIN "products" ON "products".id = "line_items".product_id WHERE (products.title like '%a%') select查询 Product.find(:all,:select=>"title,price") 相当 SELECT title,price FROM "products" readonly只读查询 >> p=Product.first => #..... >> p=Product.first(:readonly=>true) => #.... >> p.title="xxxxxxxxx" => "xxxxxxxxx" >> p.save #抛出异常 from 指定表名 group 指定分组 limit 指定条数 offset 指定起始数 find_by_sql 直接执行sql语句 获取字段统计信息 Product.average(:price) Product.maximum(:price) Product.minimum(:price) Product.sum(:price) Product.count() 动态查询 Product.find_by_title_and_price("测试",78.9) #只查第一条first 结果:title和price Product.find_all_by_title_and_price("测试",78.9) #返回数组 结果:title和price Product.find_or_create_by_title("hahahaha") #查询并保存 Product.find_or_initialize_by_title("aoiokkok") #查询,如果没有初始化 查看日志 tail -f log/development.log 原文链接:/sqlite/202301.html

猜你在找的Sqlite相关文章