ITeye博客

夜鸣猪的Ruby On Rails 空间

夜鸣猪 · 共 628 篇文章

improve rspec speed GC

#spec/support/deferred_garbage_collection.rb class DeferredGarbageCollection DEFERRED_GC_THRESHOLD = (ENV['defer_gc'] || 15.0).to_f @@last_gc_run = Time.now def self.start GC.disable if DEFERRED_GC_THRESHOLD > 0 end def self.reconsider if DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEF…

2013-01-29 05:23 · ruby · 评论(0)

how to truncate table in rails

ActiveRecord::Base.connection.execute("TRUNCATE TABLE #{table_name}")

2013-01-29 04:14 · 评论(0)

2种使用class_eval动态定义方法的格式

class MyClass def initialize(dynamic_methods) @arr = Array.new(dynamic_methods) @arr.each{|m| self.class.class_eval do define_method(m) do |*value| puts value end end } end end tmp = MyClass.new %w(method1 method2 method3) tmp.method1 'abc' class MyClass def initialize(dynamic_methods) @arr = Array…

2012-12-12 08:06 · Ruby 1.9 · ruby · 评论(0)

关于method_missing 和respond_to?的基本用法

method_missing is a well-known tool in the Ruby metaprogramming toolbox. It’s callback method you can implement that gets called when a object tries to call a method that’s, well, missing. A well known example of this is ActiveRecord dynamic finders. For example, if your User has an email attribute…

2012-12-12 07:46 · ruby · respond_to? · method_missing · 评论(0)

rails 3.1 mysql2 ubuntu

sudo apt-get install libmysql-ruby libmysqlclient-dev

2012-11-22 13:13 · Ruby On Rails · 评论(0)

Enabling Pry with reload

For anyone coming to this question recently: the answer has changed in Rails 3.2, because they've changed how they implement reload! Where in earlier version the irb commands were added as methods to Object , now they are added to IRB::ExtendCommandBundle to avoid polluting the global namespace. Wh…

2012-10-23 02:05 · Ruby On Rails · 评论(0)

heroku quick deploy

#need pg in Gemfile #sqlite3 in dev 1) gem install heroku 2) heroku login 3) heroku create 4) heroku apps:rename newapp [https://devcenter.heroku.com/articles/renaming-apps] 5) git push heroku master [https://devcenter.heroku.com/articles/git] 6) heroku run rake db:version [https://devcenter.heroku…

2012-10-18 23:07 · Ruby On Rails · Postgresql · 评论(0)

ruby 1.9.3-p286 debugger-linecache

update(05/13/2013) rbenv: 解决方案: gem install debugger-linecache -- --with-ruby-include=/home/user/.rbenv/versions/1.9.3-p392 gem install ruby-debug19 -- --with-ruby-include=/home/user/.rbenv/versions/1.9.3-p392 Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /home/r…

2012-10-18 21:10 · Ruby 1.9 · 评论(0)

rails 下自定义配置变量

APP_CONFIG = YAML.load_file("#{Rails.root}/config/config.yml")[rails.env] #rails3 MyApp::Application.config.custom_config_variable = :my_config_setting or Rails.configuration.custom_config_variable = :my_config_setting #need initialization files or the environment.rb YourApp::Application.configure …

2012-10-18 07:36 · Ruby On Rails · 评论(0)

MAC 和 Postgresql 第二篇

非常有用的相关资料 UPDATE(05/06/2013): still works fine for MAC modify /usr/local/var/postgres/postgresql.conf get localhost works pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log restart 还是说brew安装,之前之后的事 用brew安装postgresql,很忌讳rvm的gcc,要用xcode的command line brew装完要设置路径,就是local那个不然,就会莫名其妙…

2012-10-16 11:56 · Postgresql · 评论(0)

Brew Install Postgresql on OS X Lion

psql: could not connect to server: Permission denied Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"? createuser: could not connect to database postgres: could not connect to server: Permission denied Is the server running locally and …

2012-10-12 21:08 · Ruby On Rails · 评论(0)

Mac OSX 和 posgresql (2013再次更新版)

UPDATE(2013/06/01) brew services restart postgresql psql -U kenlu -h localhost -d postgres 几个重要说明: mac 下brew安装后要initdb 启动后,默认管理员是系统当前帐户 psql不认的时候,就是brew的路径问题(见下代码) brew装的重启,启动什么的用brew services 在ubuntu下完全不同sudo aptitude 安装后,不许要initdb只要 sudo -u postgres psql template1 template1=# CREATE USER tom WITH…

2012-10-03 05:03 · Ruby On Rails · Postgresql · 评论(0)

rspec小抄

# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com # defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below) module Player describe MovieList, "with optional description" do it "is pending example, so that you can write ones quickly" it "is already wor…

2012-10-01 21:58 · 评论(0)

Postgresql 和 rails

update(05/13/2013) ubuntu only ALTER USER postgres with encrypted password 'your_password'; #/etc/postgresql/9.1/main/postgresql.conf #localhost Locate the line #listen_addresses = 'localhost' and change it to: listen_addresses = 'localhost' sudo -u postgres psql template1 \du list user 这里注意ubuntu下…

2012-09-24 02:46 · Ruby On Rails · Postgresql · 评论(0)

OpenSSL Errors and Rails – Certificate Verify Failed

Update:11/09/2012 有同鞋求摘要如下: 遇到类似错误,在使用或调用SSL的API时候, RVM怎么用呢 Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError) Gem::RemoteFetcher::FetchError: SSL_connect returned=1 …

2012-09-22 01:29 · Ruby On Rails · 评论(0)