`
zzhang
  • 浏览: 17674 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论
文章列表
以后不会在这里更新博客,博客地址转移到 http://zhangzhe.heroku.com/。
no need download cheat anymore:) in install: sudo gem install cheat use: cheat <sheet name> see all: cheat sheets help: cheat cheat
used "rails best practices " today. details see: http://github.com/flyerhzm/rails_best_practices     below are the refactor advices for my app :./config/routes.rb:58 - not use default route ./config/routes.rb:59 - not use default route ./app/sweepers/backup_sweeper.rb:4 - law of de ...
1.old code def page_group_toolbar(page_group) c = "" case page_group.class_name when "Preparation" c << li_link_to(t("Preparation"), admin_self_study_page_groups_path(:scenario_id=>page_group.scenario.id, :type=>"preparation"), true ...
refactor below code:   def preparation?(page_group) page_group.class_name == "preparation".camelize end def task_card?(page_group) page_group.class_name == "task_card".camelize end def extra_content?(page_group) page_group.class_name == "e ...
Use sometime to learn stub and mock. I think below is a good example:   code: def create_from_content(content) page_content = PageContent.new(content) templet = page_content.templet templet_id = page_content.templet_id page_title = page_content.page_title #O ...
1.stub meet "one to many" relationship   Here is the code: describe "original_content" do it "should generate page_group's original_content" do page_group = PageGroup.create page1 = page_group.pages.create page1.stub!(:content).and_return(&q ...
apt: apt-cache search package 搜索包 sudo apt-get install package 安装包 sudo apt-get install package - - reinstall 重新安装包 sudo apt-get remove package 删除包 sudo apt-get update 更新源 fuser: fuser -k -n tcp port   ps: ps aux|grep firefox   scp: scp -r xxx@xxx.xxx.com:/home/app/xxxs . sc ...
In order to name method like a pro, I create this stupid method in Page model:   def to_xml(type = nil) case type when :flex # ... when nil super() end end   So later when I use:   render :xml => page.to_xml(:only => [ :id, :scenario_id, :title], :include=> :pag ...
A bug take a long time to find out. I had a method like:   def file_not_exsit_with?(url) require 'open-uri' return open(url).read =~ /^Status: 500 Internal Server Error/ rescue puts "#{url} not exists!".center(66, "=") # return true # I missed this line end ...

use screen

Doing long time rake, screen is a good assistant.     screen -S + name         start screen with name screen -r + name          resume a screen screen -D + name        detach an attached screen Ctrl + a c                        create new screen Ctrl + a n                        next screen ...
some ruby tricke:     1.shorter regular expression string = "I am strong..." puts string[/(.*?)(\.+)/, 1]   # => I am strong   2.add methods to class class String def test1 "test1" end end puts "".test1   # => test1   3.rescue in method ...
I wrote some gems in my project, but testing them is a big pain. Everytime I want to make sure all functions work, I need to make a test model outside gem and test there.   Here is one solution: make a spec folder in gem. Take test string_extension.rb as example.   In spec/string_extension_sp ...
Spend a week for data migration.  Here are some things I learned: 1. class OldScenario < ActiveRecord::Base establish_connection configurations['old_db'] set_table_name(connection.current_database + "." + "scenarios") has_many :old_ ...
学习ruby on rails 两年了,期间使用过Eclipse和Netbeans,半年以前开始使用emacs。 经过刚开始的不适,半年来不断到处拷代码,改配置。最近感觉逐渐使得顺手了。 把配置贴出来做一个记录,也希望能对其他人有启发或者帮助 model: view: 自定义常用快捷键: F5               compile F12             kill buffer C-F12         kill rinari files C-w             kill one line s-m             choose model s-c    ...
Global site tag (gtag.js) - Google Analytics