随笔分类 -  ruby

rbenv Your user account isn't allowed to install to the system Rubygems
摘要:Clone一个新Rails项目到Mac, bundle install 的时候遇到下面的提示Fetching source index from http://rubygems.org/ Your user account isn't allowed to install to the syst... 阅读全文

posted @ 2015-05-30 21:27 小浪鼓 阅读(728) 评论(0) 推荐(0) 编辑

编译安装Ruby 1.9.3 安装CentOS
摘要:1. 准备需要的安装的东西yum -y install make gcc openssl-devel zlib-devel gcc gcc-c++ make autoconf readline-devel curl-devel expat-devel gettext-devel ncurses-devel sqlite3-devel mysql-devel httpd-devel wget which2 下载源文件cd /usr/srcwget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gztar zxf yaml-0.1.4.tar. 阅读全文

posted @ 2013-09-14 03:10 小浪鼓 阅读(5964) 评论(0) 推荐(0) 编辑

Ruby require, load include 区别
摘要:Require, load用于文件, *.rbrequire一般用于加载库文件,load加在配置文件,ruquire可省略“.rb",它指挥在第一次时候载入,如在字require就被忽略load加载多次include 用于包含一个文件中的模块require 'webrick' include WEBrick # 可以不用 server = WEBrick::HTTPServer.new(...) server = HTTPServer.new(...) 当你修改一段代码,不用重启服务器,你的代码被reload,这就是load的作用。如果使用require的话多次req 阅读全文

posted @ 2013-07-30 11:12 小浪鼓 阅读(478) 评论(0) 推荐(0) 编辑

gem install 和 bundle 区别
摘要:bundle install在设置了所有包含在Gemfile中的东西。你也可以传递参数。如果在production模式下,你很清晰的区分了每个app需要的gems。gem install则安装在整个环境中了。本质上讲他们是没有区别的。 阅读全文

posted @ 2013-07-23 15:12 小浪鼓 阅读(6045) 评论(0) 推荐(0) 编辑

ruby 升级1.8.7到1.9.3
摘要:rvm install ruby 1.9.3 ruby -v如果还是1.8.7.rvm use 1.9.3列出所有版本rvm list设置默认的版本 rvm --default use x.x.x 阅读全文

posted @ 2013-07-16 15:40 小浪鼓 阅读(4283) 评论(2) 推荐(0) 编辑

Ruby:Hash 排序
摘要:people = { :fred => 23, :joan => 18, :pete => 54}年龄排序:people.values.sort # => [18, 23, 54]姓名排序:people.sort_by { |name, age| age } # => [[:joan, 18], [:fred, 23], [:pete, 54]]或者people.sort一个复杂点的hashpeople = { :fred => { :name => "Fred", :age => 23 }, :joan => { :n 阅读全文

posted @ 2013-04-05 13:31 小浪鼓 阅读(1473) 评论(0) 推荐(0) 编辑

改变rails的路由中默认的id
摘要:目的: /users/2 -> /users/jack使用to_param方法。不要改变id到string类型,你需要一个属性是唯一的,比如username,无论什么。在view里面,确保传递的参数不要是id 一定要是model<td><%= link_to p.name, parse_place_path(p) %></td>不是<td><%= link_to p.name, parse_place_path(p.id) %></td>在model里面,重新 to_paramdef to_param usernam 阅读全文

posted @ 2013-01-14 16:38 小浪鼓 阅读(1090) 评论(0) 推荐(0) 编辑

今天Rails都学到了啥
摘要:打算学习rails已经好久了,这两天才认真的开始写代码,结果,哎不写不知道,一写还真有问题,不过幸好都解决了。总结下今天学到的内容:1 Rails的数组真是强大compact 这个函数压缩数组,去除数组的nil;2 join(",") 将字符串连接3 更新modelupdate_attributes 这个方法不用必须更新model的所有属性。form_for 很强大,这个是更新model必须用的。如果不更新model就用 form_tag而form_for 在 EDIT 方法中或者在NEW方法中 当<%= f.submit %>之后,会自动的路由到update 阅读全文

posted @ 2013-01-08 01:23 小浪鼓 阅读(207) 评论(0) 推荐(0) 编辑

Ruby: case 语句的使用
摘要:case n when 0 then puts 'Nothing' when 2, 7, 10 then puts 'Other Numbers' else puts 'There is nothing here'endcase name when "Jason" then puts "Hello Jason you are a valued customer, welcome back." when "Peter" then puts "Hello Peter very ni 阅读全文

posted @ 2013-01-07 23:15 小浪鼓 阅读(3577) 评论(0) 推荐(0) 编辑

respond_to 和 respond_with
摘要:转自:http://caterpillar.onlyfun.net/Gossip/Rails/RespondToWith.htmlrespond_to可以讓你根據客戶端要求的格式進行不同的格式回應,以RESTful 與 Rails中完成的應用程式首頁為例,若想要客戶端在請求http://localhost:3000/bookmarks.html、http://localhost:3000/bookmarks.xml、http://localhost:3000/bookmarks.json時,分別給HTML、XML、JSON格式回應,可以如下修改:bookmarks_controller.rbc 阅读全文

posted @ 2012-11-15 14:42 小浪鼓 阅读(4342) 评论(0) 推荐(1) 编辑

Rails Migration:更改table的行数据类型
摘要:1 生成migration文件rails g migration change_data_type_for_fieldname2 更改文件内容class ChangeDataTypeForFieldname < ActiveRecord::Migration def change change_column :talbename, :columnname, :type endend参考文档 阅读全文

posted @ 2012-11-15 14:24 小浪鼓 阅读(987) 评论(0) 推荐(0) 编辑

unicorn 无缝重启,pids目录是空的问题
摘要:使用capistrano+unicorn布署Rails网站的时候,进行到最后一步,发现/tmp/pids/下面本应该是unicorn.pid 文件的结果是空的,就会导致cap deploy的时候不能完成,/tmp/pids/unicorn.pid: No such file or directory想了想这是第一次,所以要在服务器短启动unicorn。unicorn_rails -c config/unicorn.rb -D解决了问题。参考 阅读全文

posted @ 2012-11-10 03:04 小浪鼓 阅读(361) 评论(0) 推荐(0) 编辑

git rm 之后的文件如何还原
摘要:使用git stash.1. 假定项目中有一个文件删除之git rm README.rdoc2. 执行git status显示:Saved working directory and index state WIP on master: bfcdf14 test gitHEAD is now at bfcdf14 test git3. 使用git stash list$ git stash liststash@{0}: WIP on master: bfcdf14 test git4. 拿出来使用git stash popgit stash pop 阅读全文

posted @ 2012-11-08 15:09 小浪鼓 阅读(9111) 评论(1) 推荐(0) 编辑

app/assets, lib/assets 和 vendor/assets
摘要:Pipeline assets 可以被放置到一个应用程序中这三个位置中的一个:app/assets,lib/assets或者vendor/assets.app/assets放置属于应用程序的资源,比如自选图像,JavaScript 文件和样式文件。lib/assets用于不在应用程序范围内的自有函式库,或者那些跨应用程序共通的函式。vendor/assets用于属于外部实体的资源,比如 JavaScript 插件和CSS框架的代码。 阅读全文

posted @ 2012-11-03 16:14 小浪鼓 阅读(852) 评论(0) 推荐(0) 编辑

cattr_accessor 和 attr_accessor 区别
摘要:cattr_accessor是 Ruby on Rails ActiveSupport一部分,不像attr_accessorn是Ruby的语言特色.cattr_accessor 是类级别上的attr_accessor,属于singleton方法。class Counter cattr_accessor :class_count attr_accessor :instance_countend counter1 = Counter.newcounter1.instance_count = 1counter1.class_count = 1 counter2 = Counter.newp co.. 阅读全文

posted @ 2012-11-01 15:46 小浪鼓 阅读(408) 评论(0) 推荐(0) 编辑

Library not loaded: libmysqlclient.18.dylib (LoadError)
摘要:sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib 阅读全文

posted @ 2012-09-12 22:01 小浪鼓 阅读(864) 评论(0) 推荐(0) 编辑

< 2025年4月 >
30 31 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 1 2 3
4 5 6 7 8 9 10

导航

统计

点击右上角即可分享
微信分享提示