- 浏览: 17674 次
- 性别:
- 来自: 北京
最近访客 更多访客>>
最新评论
-
dazuiba:
rails-1.2.4update to 1.2.5updat ...
诡异的"already initialized constant OPTIONS"及解决方案
文章列表
useful cheat sheets.
- 博客分类:
- rails 学习
no need download cheat anymore:)
in install:
sudo gem install cheat
use:
cheat <sheet name>
see all:
cheat sheets
help:
cheat cheat
- 2009-11-11 14:40
- 浏览 846
- 评论(0)
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 ...
- 2009-11-09 17:53
- 浏览 885
- 评论(0)
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 ...
- 2009-11-05 10:20
- 浏览 887
- 评论(0)
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 ...
- 2009-11-03 18:07
- 浏览 761
- 评论(0)
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 ...
- 2009-10-13 17:20
- 浏览 891
- 评论(0)
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 ...
- 2009-09-21 15:39
- 浏览 1016
- 评论(0)
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 ...
never use not + not.
- 博客分类:
- rails 学习
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 ...
- 2009-09-19 22:57
- 浏览 831
- 评论(0)
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 ...
- 2009-09-19 02:28
- 浏览 913
- 评论(0)
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 ...
- 2009-09-08 12:28
- 浏览 797
- 评论(0)
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_ ...
- 2009-08-20 13:57
- 浏览 838
- 评论(0)
学习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 ...
- 2009-08-03 15:45
- 浏览 1971
- 评论(0)