Seems like the most trivial thing to do, but I could not find any information about changing the sort order when sending multipart emails from devise.
First, create a custom mailer for devise https://github.com/plataformatec/devise/wiki/How-To:-Use-custom-mailer
Then add parts_order to the default hash.
1 2 3
| class DeviseMailer < Devise::Mailer
default from: 'user@domain.com', parts_order: [ "text/plain", "text/html" ]
end |
Thats it. And oh, this works for any other mailer to.
Posted in
Programming at March 27th, 2013.
No Comments
Tagged with
devise,
mailer,
Rails. Written by:
stjernstrom
When you have a table with serialized columns active record will always treat them as dirty. It can create unnecessary overhead when just incrementing a simple counter.
Fortunately rails has a method that just update the counter and nothing else.
apidock: update_counters
If you have a Movie model with a counter named like_count and you would like to increment it by one you would use the following method.
1
| Movie.update_counters id, :like_count => 1 |
As a bonus you also get a locking
Posted in
Programming,
Rails at May 19th, 2012.
No Comments
Tagged with
activerecord,
Rails,
tip. Written by:
stjernstrom
Today I decreased my Ruby On Rails boot time by ~60%, Yay!
(All credit goes to funny-falcon for the patches and Burke who posted the Gist)
I removed 26 gems from my Gemfile and I noticed a boost with a couple of seconds. From that I begun searching for large Gemfile problems and I stumbled on this gist https://gist.github.com/1688857
It a pretty long page, so I will just summarize how I got my 60%
I use ruby 1.9.3-p125 and rbenv and ruby-build for handling ruby.
First we need to create a manifest file for our new patched ruby
Create a file named ruby-1.9.3-perf with the following content
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| build_package_combined_patch() {
local package_name="$1"
{
curl 'https://raw.github.com/gist/1859082/performance_and_backport_gc.patch' | patch -p1
autoconf
./configure --prefix="$PREFIX_PATH" $CONFIGURE_OPTS
make -j 8
make install
} >&4 2>&1
}
require_gcc
install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz"
install_package "ruby-1.9.3-p125" "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz" combined_patch |
When we have our manifest file in place we can use ruby-build to build ruby
1
| ruby-build ./ruby-1.9.3-perf ~/.rbenv/versions/ruby-1.9.3-p125 |
And here is my final results!
1 2 3 4 5 6 7 8 9 10 11 12 13
| Before
time -p bundle exec rake environment
real 6.81
user 5.93
sys 0.85
After
time -p bundle exec rake environment
real 3.75
user 2.82
sys 0.91 |
All credit goes to funny-falcon for the patches and Burke who posted the Gist.
Posted in
Rails,
Ruby at February 29th, 2012.
3 Comments
Tagged with
optimize,
performance,
Rails,
Ruby. Written by:
stjernstrom
Just before christmas I worked with one of our customers new server cluster or cloud if you may.
This cluster has production nodes and staging nodes and this post is about how to get capistrano to play nice with both production and the staging environment.
Read More…
I got so tired of all the messy capistrano output so today I released my first public gem.
The name of the gem is capistrano_colors and the aim of the gem is to put some nice and shiny colors on capistrano output. The gem has only been tested with rails but should work wherever capistrano works.
Keep on reading to see some screenshots!
Read More…
Finally my friends at newsdesk have a blog. They have started off real good with a comparison of three ruby wrappers for Google charts.
I have great expectations from the newsdesk developers blog. If you are a Ruby and Rails developer you should definitely keep and eye on them!
Posted in
Life,
Rails,
Ruby at November 25th, 2008.
No Comments
Tagged with
blog,
charts,
google,
Rails,
Ruby. Written by:
stjernstrom
Today one of our server got in trouble with an ACE encoded IDN domain. The problem seemed to be rails in combination with nginx’s X-Sendfile feature. The result became that when accessing the site trough the IDN domain x-senfile did not send any files….
Our quick and dirty solution (until we have found the source/or solved the problem) became redirecting all traffic from the IDN domain to the domain without strange-swedish-characters.
With nginx this is as simple as in most webservers just put the following code before you original server configuration in nginx.conf.
1 2 3 4
| server {
server_name xn--svenskdomn-y5a.se www.xn--svenskdomn-y5a.se;
rewrite ^(.*) http://www.svenskdoman.se$1 permanent;
} |
And Bowang! All requests to www.svenskdomän.se will be redirected to www.svenskdoman.se.
Domain names have been changed to protect the innocent
Cheers!
Posted in
Hosting,
Rails at May 21st, 2008.
No Comments
Tagged with
Hosting,
nginx,
Rails. Written by:
stjernstrom