Rails 学习了近两个星期的 ruby on rails,简单的 CURD 到部署到服务器的学习总结

匿名 · 2013年08月01日 · 最后由 huberydu 回复于 2013年08月02日 · 6260 次阅读

rails 教程 http://ihower.tw/rails3/

http://railstutorial-china.org/

ruby on rails 的环境搭建 https://www.digitalocean.com/community/articles/how-to-install-ruby-on-rails-on-ubuntu-12-04-lts-precise-pangolin-with-rvm

nginx 的环境搭建与配置

  • 安装 nginx gem install passenger rvmsudo passenger-install-nginx-module
  • 安装启动 nginx 脚本

    wget https://raw.github.com/gist/1548664/53f6d7ccb9dfc82a50c95e9f6e2e60dc59e4c2fb/nginx

    sudo cp nginx /etc/init.d/

    sudo chmod +x /etc/init.d/nginx

    sudo update-rc.d nginx defaults

  • nginx 的配置 server { listen 80; //端口号 server_name localhost;//域名

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / { root /home/xiaolong/workspace/skynet/public;//项目public的绝对路径 index index.html index.htm; passenger_enabled on; //是否允许 passenger 插件的使用 rails_env development;//指定发布模式,默认为 production,如果为 production 的话就要先 precompile rails assets 下 } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }

参考 安装 nginx https://hisea.me/p/rails31-ubuntu-passenger-nginx-quick-deploy

环境配置 http://blog.enjoyrails.com/2009/05/22/195

403 错误解决方法http://ruby-china.org/topics/4523

capistrano 的配置

  • 安装 capistrano gem install capistrano
  • 创建相关文件 capify .
  • 配置 deploy.rb

    require 'rvm/capistrano' # 支持 rvm require 'bundler/capistrano' # 支持自动 bundler set :rvm_autolibs_flag, "read-only" # more info: rvm help autolibs

    set :application, "skynet" #应用的名字 set :keep_releases, 10 set :location, "0.0.0.1" #部署的 ip 地址 set :location, "www.netpom.com" role :web, location # Your HTTP server, Apache/etc role :app, location # This may be the same as your Web server role :db, location, :primary => true # This is where Rails migrations will run #role :db, "3dtzk.com"

    #server details default_run_options[:pty] = true # Must be set for the password prompt set :deploy_to, "/home/xiaolong/skynet.com" #部署在服务器上的地址

    set :user, "xiaolong" #ssh 连接服务器的帐号 set :use_sudo, false set :ssh_options, { :forward_agent => true } #repo details set :scm, :git # Or: accurev, bzr, cvs, darcs, git, mercurial, perforce, subversion or none set :scm_username, "HuberyDu" #github 帐号 set :scm_passphrase, "xxxx" #设置 github ssh 时设置到密码 set :repository, "[email protected]:dreamlx/skynet.git" #项目在 github 上的帐号 set :branch, "master" #github 上具体的分支 set :deploy_via, :remote_cache

    #tasks namespace :deploy do task :restart, :roles => :app do run "touch #{current_path}/tmp/restart.txt" end

    task :stop, :roles => :app do #do nonthing end

    desc "Symlink shared resources on each release - not used" task :symlink_shared, :roles => :app do #run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" end

    task :precompile, :roles => :web do
    run "cd #{current_path} && #{rake} RAILS_ENV=production assets:precompile"
    end

    end

    after "deploy:update", "deploy:migrate" after "deploy:migrate", "deploy:symlink_shared" after "deploy:migrate", "deploy:precompile"

然后把修改过的内容提交到 git 上 第一次部署 $ cap deploy:setup $ cap deploy:check $ cap deploy:migrations 发布 cap deploy

参考https://github.com/capistrano/capistrano/wiki http://ruby-china.org/topics/6424

学习了近两个星期了,挺喜欢这门语言的

很好,不过建议楼主在稍微研习一下 markdown 的排版技巧。

匿名 #2 2013年08月01日

#1 楼 @lgn21st 恩,好的,等会去看看

不错,我也学习了两个星期。不过都是晚上下班才有时间学。现在从事测试,想转开发! 加油

匿名 #4 2013年08月01日

#3 楼 @JohnLu 我现在是实习生,感觉英文不好,学这个挺麻烦的,基本上都是国外的资料

安装 nginx gem install passenger rvmsudo passenger-install-nginx-module

这对吗?

#6 楼 @huberydu 你好,打扰以下,请问下你是怎么找实习的。我最近刚学习了一个来月,很想和别人交流,前天也写了一篇自己的学习小节,欢迎指点。rails 要学的东西真多,虽然学的还不算太吃力,但总感觉自己窝家里学太低效,想赶紧把入门知识掌握个大概就去找个实习,实践中敏捷及时的正反馈才高效。


我把 railstutorial 过了两遍,按书上的搭在了heroku上,自己加了给微薄显示回复和楼层。英文凑合,railscasts 能听,api 能看。在实现回复楼层功能时,发现自己 js 和 Ajax 不行没法实现。你是怎么学的,能分享学习下么,谢谢

由于项目需要,也大概也花了 2 周的时间边改代码边学习 ROR 的

匿名 #9 2013年08月02日

#7 楼 @lafmad http://weibo.com/1866007613/zExJwocj0?mod=weibotime 七月份准备去找工作的时候发了份求职微薄,挺多人转发的,就有好几家公司打电话给我,然后就挑了个最适合自己的!

需要 登录 后方可回复, 如果你还没有账号请 注册新账号