下面这段代码: <td><%= consumption_entertainment.entertainment.name %> <td><%= consumption_entertainment.cost %> <td><%= consumptio...
[草稿]capistrano的原理
裸代码:   没有数据库的配置文件,  没有服务器相关的配置文件,  也没有压缩各种css/js , 一般都是从git上直接clone下来的代码.  传统的部署步骤:       1. ssh 到服务器.  2.  git pull .  3. restart  comma...
如何打印ruby的动态代码
refer to:  http://stackoverflow.com/questions/1675053/printing-the-source-code-of-a-ruby-block ruby最强的地方(之一)在于 meta programming. 那么了解到动态的代码的具体内容就很重要 默认ruby不提供  proc.inspect 这样的方法.还好 社区的战...
Ruby 进行数字加减时,不要换行
sum = self.bonus + @staff.wage/(self.attendance + self.leave)*self.attendance - self.tax - self.pension - self.medicare - self.u nemployment rescue 0就可以。 sum = self.bonus     ...
抓取并且分析远程的接口的数据
以抓取 PPTV 在 豌豆荚的首页 的排名为例子。 1. 先把手机连接到 charlse上  (参考:这里) 。 2. 然后,打开豌豆荚(需要安卓手机), 找到对应的接口(可以通过搜索PPTV 这个关键字找到) 3. 这个接口就是: http://112.5.16.36:3011/wdj/http://startpage.wandoujia.com/api/v1/fetch?f=p...
Rails Has_manybelongs_to中的conditions的写法
参考: https://stackoverflow.com/questions/20307874/what-is-the-equivalent-of-the-has-many-conditions-option-in-rails-4 在 Rails2/3 中, has_many 可以包含 conditions  在 Rails 4+ 中,需要写成 ->, 例如: class...
[教程]web+rails入门2(大师原创)ruby10分钟入门
ruby 的基础: 声明个class:  class Apple @color = '' def color return @color end def color= (new_color) @color = new_color end # 以上代码可以简写为: attr_accessible :color @@name = 'ap...
Rails中使用devise
refer to:  https://github.com/plataformatec/devise 总论:  下面仅仅是个大概的思路,要多看文档.  2018.4.18 , devise将近2W个关注了. # Gemfile gem 'devise' # 运行下面三个命令 $ bundle exec rails generate devise:insta...
Ruby 根据年 月来获取每个月份第一天和最后一天
参考: https://stackoverflow.com/a/43892850 year = 2017 month = 5 require 'date' Date.new(year, month, 1) #=> #<Date: 2017-05-01 ...> Date.new(year, month, -1) #=> #<Date: 2017-05-31...
Railsspring:另一个railssprocketwatch.极大节省你的时间
2010/2011年左右,我尝试过使用 rails sprocket/watch, 确实能快速节省时间。 缺点是每次修改完 config 文件之后,必须重新启动 sprocket server. 如果不启动,就会产生各种麻烦。 而且我个人是个喜欢 随时保存( :w ) 的人,所以每次保存vim都会引起不必要的报错,让我对这个不太感冒。 不过今天还是试试spring 吧,毕竟  ti...
使用factorygirl
refer to: http://www.rubydoc.info/gems/factory_girl/file/GETTING_STARTED.md factory girl的出现是为了取代rails自带的 fixtures.  后者的启动速度慢,关联关系设置的会特别麻烦。 安装: (见: http://stackoverflow.com/questions/23850979/...
Rails 解决rails4的接口跨域问题
让接口的response的header中返回一些东西就可以: class Interface::ApplicationController < ActionController::Base after_filter :set_access_control_headers def set_access_control_headers headers['Access-C...
使用jeditable
refer to:  http://www.appelsiini.net/projects/jeditable 注意: 放弃使用 rubygem 吧, 里面没有啥内容。  用法: 下载文件:http://www.appelsiini.net/download/jquery.jeditable.js 并且把 js 文件做好配置后: <p class="jedita...
Windows Xp下使用ruby的注意事项sinatra不能用。气死我了。rails就可以。记录在了github上。
在这里:   https://github.com/sg552/sinatra_not_work_on_windows 教训: 一个框架不行的时候,赶紧换另一个,不要深究原因。windows 无道理可讲...  用ruby 1.9.3  rails 2.3.5  win xp 下使用 sublime .   xp 下不能安装 git bas...
Handsontable:不错的excelstyletableplugin
refer  to http://www.sitepoint.com/7-jquery-microsoft-excel-type-plugins/ 注意: 直接 wget js, 然后使用asset 引用。 不要用: rails plugin:  https://github.com/mahinder/rails_handsontable   否则...
一丢丢思考(thinkingaboutgrammar)
1. 为什么行末尾要加分号?  为什么每个方法结束要放(), {} ?  2. 为什么 声明变量,常量,数组的方法不一样? var $apple = 'apple'; define('APPLE', 'an apple'); $apples = array('apple1', 'apple2', 'apple3'); 像ruby, js 那样一个写法多好:  $...
Ruby Stdout.sync=true的含义
参考:https://stackoverflow.com/questions/29998728/what-stdout-sync-true-means 就是让控制台立即输出内容。 而不是缓存一小段时间后统一输出。 在建立websocket server的时候特别有用。
Todovim提高班资源
refer to:  http://vimawesome.com/, https://ruby-china.org/topics/25295?page=1#replies, tag list , 一直是我心中的痛。。。 记录下来,有空弄完它。 </span>
Ruby 单点服务器,rubycasserver
已经放github上了:   https://github.com/sg552/rubycas-server
使用rails_config来管理配置选项
refer to:  https://github.com/railsconfig/rails_config 项目中很多常量 ( system constant) 都应该配置成 配置选项  (config items)  系统常量:  在系统运行时是固定值,并且在每个开发人员的机器上都相同。 例如:black='#ffffff' 配置选项: ...