Home

How to see data in rails session

cookie = "BAh7CiIHdHQiQWJVaDlPTnlzeFAwT1J5eGZhOFNIVmV4aWR1RkFTZDdXVURmTHhOTnB2czVjVnZ0WFB2VXpRbEFITDZreiIQX2NzcmZfdG9rZW4iMS9UK0V0clZOUmgrVWp2M2Z0WkNWaHQxUWxtU3B1LzZBd3NTYjdJR0RkT1k9IhRsYXN0X3JlcXVlc3RfYXR1OglUaW1lDcXrG4BhsqGyIg9zZXNzaW9uX2lkIiUzZjg3NmVlM2VjMGJlOGViMjUyMDBhOThiM2VjNzU4NiITdXNlcl9yZXR1cm5fdG8iJi9teS9ydW5uaW5nP2ludGVydmFsPSZwZXJfcGFnZT0zMA%3D%3D--6490870d9173feeb8b92940740eadb30d740df25"

session_content, signature = cookie.split("--")

# Then you got the session content
session_hash = Marshal.load Base64.decode64 session_content

So please remember don’t store sensitive data in session or signatured cookie, it’s actually not safe.


Add ruby load path

Only after you add load path, then you would be able to require 'xxx.rb'

$: << File.expand_path(File.dirname(__FILE__))

Config sample for Unicorn plus assets pipeline work with ngixn

upstream app {
  server unix:/srv/app/current/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
        listen   80;
        server_name  www.app.com;
        rewrite ^/(.*) http://app.com/$1 permanent;
}

server {
  listen 80;
  client_max_body_size 2G;
  server_name app.com;
  keepalive_timeout 5;
  root /srv/app/current/public;
  access_log  off;
  error_log off;

  if ($request_method !~ ^(GET|HEAD|PUT|POST|DELETE|OPTIONS)$ ){
    return 405;
  }

  location ~ ^/(assets)/  {  
    gzip_static on;
    expires     max;
    add_header  Cache-Control public;
  } 

  location / {
    try_files $uri/index.html $uri.html $uri @app;
    error_page 404              /404.html;
    error_page 422              /422.html;
    error_page 500 502 503 504  /500.html;
    error_page 403              /403.html;
  }

  location @app {
    proxy_pass http://app;
  }

  location = /favicon.ico {
    expires    max;
    add_header Cache-Control public;
  }

  location ~ \.php$ {
    deny  all;
  }
}

Capistrano with rvm installed on server

Add below code to “deploy.rb”

require "bundler/capistrano"
$:.unshift(File.expand_path("./lib", ENV["rvm_path"]))
require "rvm/capistrano"
# specify the ruby version
set :rvm_ruby_string, "ruby-1.9.2-p180"
# rvm installed at 'system' or 'user' level
set :rvm_type, :user

You can look at this article


how to stop run apache at startup

$ sudo update-rc.d apache2 disable

update-rc.d: warning: apache2 start runlevel arguments (none) do not match LSB Default-Start values (2 3 4 5)
update-rc.d: warning: apache2 stop runlevel arguments (none) do not match LSB Default-Stop values (0 1 6)
 Disabling system startup links for /etc/init.d/apache2 ...
 Removing any system startup links for /etc/init.d/apache2 ...
   /etc/rc0.d/K09apache2
   /etc/rc1.d/K09apache2
   /etc/rc2.d/S91apache2
   /etc/rc3.d/S91apache2
   /etc/rc4.d/S91apache2
   /etc/rc5.d/S91apache2
   /etc/rc6.d/K09apache2
 Adding system startup for /etc/init.d/apache2 ...
   /etc/rc0.d/K09apache2 -> ../init.d/apache2
   /etc/rc1.d/K09apache2 -> ../init.d/apache2
   /etc/rc6.d/K09apache2 -> ../init.d/apache2
   /etc/rc2.d/K09apache2 -> ../init.d/apache2
   /etc/rc3.d/K09apache2 -> ../init.d/apache2
   /etc/rc4.d/K09apache2 -> ../init.d/apache2
   /etc/rc5.d/K09apache2 -> ../init.d/apache2