Archive for June, 2012

26
Jun
12

change timezone without changing time


t = DateTime.now
t.change(:offset => "+0800")

will change the timezone to a +0800 one.

25
Jun
12

rendering a jbuilder template to a string

Here’s how:


#controllers/users_controller.rb
def index
  @users = User.all
  @users_json = render_to_string( template: 'users.json.jbuilder', locals: { users: @users})
end

#views/users/users.json.jbuilder
json.array!(users) do |json, user|
  json.(user, :id, :name)
end

Thanks to Aaron Renoir

22
Jun
12

Dalli unmarshal error

I’ve kept receiving errors like: DalliError: unable to unmarshal value.
The solution was to add all the unmarshable classes in the relevant controllers, like this:


require_dependency "some_model_that_cannot_be_unmarshalled"
20
Jun
12

rails delete table from console


ActiveRecord::Migration.drop_table(:users)
09
Jun
12

emacs 24 ubuntu


sudo add-apt-repository ppa:cassou/emacs

sudo apt-get remove `apt-cache search emacs | awk '{print $1}'` --purge

sudo apt-get -f install # don't list packages here

sudo apt-get remove emacs-snapshot --purge

sudo apt-get autoclean

sudo apt-get autoremove

sudo apt-get update

sudo apt-get install emacs-snapshot

Information found: here

09
Jun
12

ruby, rvm and ubuntu

Here’s how to get a working installation of rvm on ubuntu:


sudo apt-get install curl git-core

sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion libcurl4-gnutls-dev postgresql postgresql-contrib libpq-dev

curl -L get.rvm.io | bash -s stable --ruby

Next, add a user to postgresql:


sudo -u postgres createuser --superuser john
sudo -u postgres psql postgres
\password john
\q

And add this to your .bashrc:


[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm



Blog Stats

  • 216,787 hits