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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # See: # - http://en.wikipedia.org/wiki/Nginx # - http://wiki.codemongers.com/NginxGettingStarted # - http://wiki.codemongers.com/NginxInstallOptions # - http://wiki.codemongers.com/NginxCommandLine # - http://wiki.codemongers.com/NginxConfiguration export PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin" mkdir -p ~/Desktop/Nginx cd ~/Desktop/Nginx curl -L -O http://sysoev.ru/nginx/nginx-0.7.2.tar.gz tar -xzf nginx-0.7.2.tar.gz curl -L -O http://downloads.sourceforge.net/pcre/pcre-7.7.tar.gz tar -xzf pcre-7.7.tar.gz cd ~/Desktop/Nginx/nginx-0.7.2 ./configure --help ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/sbin --with-debug --with-http_ssl_module --with-pcre=../pcre-7.7 make sudo make install which nginx otool -L /usr/local/sbin/nginx open /usr/local/nginx open -e /usr/local/nginx/conf/nginx.conf nginx -v nginx -V sudo nginx # start server sudo nginx -t open http://localhost:80 open http://localhost:80/50x.html sudo nano /usr/local/nginx/conf/nginx.conf # editing ... server { listen 8080; ... # reload configuration sudo kill -HUP `cat /usr/local/nginx/logs/nginx.pid` # stop server sudo kill -15 $(ps -auxxx | egrep "[n]ginx.*master" | awk '{ print $2 }') 2>/dev/null |
Category : Ruby on Rails
Category : Ruby on Rails
Handy little helpers to check if a file was provided to a controller, and to save it.
1 2 3 4 5 6 7 8 9 10 11 | def file_provided? [StringIO, Tempfile].include?(@file.class) and @file.size.nonzero? end def save_file if @file.is_a? Tempfile FileUtils.cp(@file.path, path) elsif @file.is_a? StringIO File.open(path, "wb") { |disk_file| disk_file << @file.read } end end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ## just slap this in your rake file or in lib/tasks namespace 'views' do desc 'Renames all your rhtml views to erb' task 'rename' do Dir.glob('app/views/**/*.rhtml').each do |file| puts `svn mv #{file} #{file.gsub(/\.rhtml$/, '.erb')}` end end end ## or if you have rhtml and rxml you could probably use the following (untested) namespace 'views' do desc 'Renames all your rhtml views to erb' task 'rename' do Dir.glob('app/views/**/*.rhtml').each do |file| puts `svn mv #{file} #{file.gsub(/\.(rhtml|rxml)$/, '.erb')}` end end end |
1 2 3 4 5 6 7 8 | require ‘uri‘ task :after_deploy do source = repository dest = URI.parse(repository).merge(“../releases/#{File.basename(release_path)}“) cmd = “svn copy –revision=#{revision} –quiet –message \”Auto tagging release #{release_path}\” #{source} #{dest}“ puts cmd `#{cmd}` end |
First, we start by requiring uri, because Subversion does not like relative URLs. Next, we find the location into which to tag the release, and finally, we just do it. Simple, effective. Enjoy !
For your unit & functional tests you have to provide input data to your test files and you do that through fixtures. The script below extracts the data from the development data base and puts it to the fixture file for each table.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | namespace :db do desc 'Create YAML test fixtures from data in an existing database. Defaults to development database. Set RAILS_ENV to override.' task :extract_fixtures => :environment do sql = "SELECT * FROM %s" skip_tables = ["schema_info", "sessions"] ActiveRecord::Base.establish_connection tables = ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : ActiveRecord::Base.connection.tables - skip_tables tables.each do |table_name| i = "000" File.open("#{RAILS_ROOT}/test/fixtures/#{table_name}.yml", 'w') do |file| data = ActiveRecord::Base.connection.select_all(sql % table_name) file.write data.inject({}) { |hash, record| hash["#{table_name}_#{i.succ!}"] = record hash }.to_yaml end end end end |
Category : Ruby on Rails
If you’ve ever been working on a Rails application and found yourself [stupidly] slipping in your testing, We have just the tool for you. Using rake and rubyosa, you can now automatically post your Code to Test Ratio as your iChat status message—meaning you can now use shame and self-humiliation to keep you motivated. After you’ve installed rubyosa, add shame.rake to your lib/tasks directory. The file contains:
1 2 3 4 5 6 7 8 9 10 11 12 | require 'rbosa' require 'code_statistics' task :shame do stats = CodeStatistics.new(*STATS_DIRECTORIES) code = stats.send :calculate_code tests = stats.send :calculate_tests ichat = OSA.app('ichat') msg = "Code To Test Ratio: 1:#{sprintf("%.1f", tests.to_f/code)}" ichat.status_message = msg $stderr.puts %|iChat status set to: #{msg.inspect}| end |
Category : Ruby on Rails
Here are the rails cheatsheet’s which will help you to get a good overview of how things work in RAILS.





