OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3 read server hello A: tlsv1 alert internal error)

require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

# Mechanize
m = Mechanize.new
m.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
page = m.get(url)

Capistrano Rails console

# cap production rails:console
namespace :rails do
  desc "Run the console on a remote server."
  task :console do
    on roles(:app) do |h|
      execute_interactively "RAILS_ENV=#{fetch(:rails_env)} bundle exec rails console", h.user
    end
  end

  def execute_interactively(command, user)
    info "Connecting with #{user}@#{host}"
    cmd = "ssh #{user}@#{host} -p 22 -t 'cd #{fetch(:deploy_to)}/current && #{command}'"
    exec cmd
  end
end

Инсталиране на Ruby 2.1 с rbenv на DreamHost споделен хостинг

git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
mkdir ~/.rbenv/BUILD_TEMP
unset GEM_HOME
unset GEM_PATH
export MAKE_OPT=-j2

TMPDIR=~/.rbenv/BUILD_TEMP RUBY_CONFIGURE_OPTS=--with-openssl-dir=/usr/include/openssl rbenv install 2.1.3

Добавяте в .bash_profile

#rbenv
unset GEM_HOME
unset GEM_PATH
export PATH=~/.rbenv/bin:"$PATH"
eval "$(~/.rbenv/bin/rbenv init -)"

Изпълнявате:

source .bash_profile
rbenv local 2.1.3

Готово! 🙂

$ruby -v
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]

Сега да инсталираме bundler:

gem install bundler --no-ri --no-rdoc

Rails Model scope with belongs_to association

class Feed < ActiveRecord::Base
  has_many :posts, dependent: :destroy
end
class Post < ActiveRecord::Base
  belongs_to :feed

  scope :only_active_feed, lambda { |active|
    joins(:feed).where(feeds: {active: active})
  }
end
  Post.only_active_feed(true)

Промяна на Time и Date формат по подразбиране в Rails

Искате да промените формата на Time и Date в rails приложение –  по подразбиране.

За целта, трябва да създадете нов initializer:

# config/initializers/time_date_formats.rb
Date::DATE_FORMATS[:default] = "%Y-%m-%d"
Time::DATE_FORMATS[:default] = "%Y-%m-%d"

Ако пък искате формата да зависи от езика и използвате i18n за локализация:

# config/locales/en.yml
en:
  time:
    formats:
      default: "%H:%M"
  date:
    formats:
      default: "%m/%d/%Y"