Francisco Saez

month

April 2011

9 posts

Cleaning ActiveRecord session data

After a few months, my web app was running increasingly slower. The statistics said that the SQL statement with the slowest response time is the one than gets the user session info.

I’m using the ActiveRecord session storage. The problem is Rails doesn’t delete old session records, so there were more than 200.000 in the table. I’ve decided to keep only the last week records, adding the following cron task:

ActiveRecord::SessionStore::Session.destroy_all(["updated_at<?", 7.days.ago])

Problem solved by now.

Apr 27, 20114 notes
#RoR #ActiveRecord
Serving Rails apps on Windows with Mongrel and Apache

If you want to serve a Rails web application on a Windows server, using Internet Information Server is not a good idea. You’ll need to install and set up a FastCGI component to do that, and you will have different issues depending on the Windows and IIS versions. There’s no recent info in the internet and, even if you get it, performance won’t be acceptable for a good number of users.

So, what’s the best solution? Easy. Run your web app with a Mongrel service and serve it through an Apache proxy.

1. Install Mongrel and the gem that will allow you to create the service:

c:\>gem install mongrel mongrel_service

2. Install Apache. Apache uses the port 80 as the default one to serve web apps. If you’re already using IIS on port 80, you’ll need to change it, for example, to port 81. Just edit the httpd.conf file to do that.

Listen 81

3. Create a Mongrel service for serving the Rails app on port 3000, for instance:

c:\>mongrel_rails service::install -name my_app -p 3000

4. Set up Apache to proxy the Mongrel service. Edit again the httpd.conf file, adding the following:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost *:81>
  ServerName localhost
  DocumentRoot "C:/dev/myapp/public"
  ProxyPass / http://localhost:3000/
  ProxyPassReverse / http://localhost:3000/
  ProxyPreserveHost On
</VirtualHost>

I’m supposing you’ve configured Apache to use the port 81, you’ve run Mongrel using the port 3000 and your app is located on c:/dev/myapp.

Apr 26, 201110 notes
#RoR #Windows #Apache #Mongrel
Reasons and Tips to Say NO  → facilethings.com

Why is so difficult for us to say no? 9 reasons to do it.

Apr 25, 20112 notes
#productivity
6 Benefits of Using GTD in Business → facilethings.com

What if workers would be taught to use a self-management methodology like GTD? It’s time to create productive enterprises.

Apr 18, 20117 notes
#gtd #productivity #e20
"Important" actions in FacileThings → facilethings.com

A new feature to define important actions is introduced in FacileThings.

Apr 14, 20110 notes
#gtd #productivity #FacileThings
Connecting a Rails app on Windows to SQL Server

I thought that connecting a Ruby on Rails application on Windows   to an SQL Server database  would be easy, just a sort of setting up an ODBC data source and the database.yml file properly. However, some issues not excessively documented in the internet have been turned up. So I‘ve written a small guide that may be of help to anyone trying to do the same:

(1) For this to work properly, first you need to install the DevKit. Just download the executable from RubyInstaller and run it. If it’s installed on C:\DevKit, for example, then follow the next steps:

cd C:\DevKit
ruby dk.rb init
ruby dk.rb install

(2) Install the ruby-odbc gem for accessing ODBC data sources:

c:\>gem install ruby-odbc

(3) Install the activerecord-sqlserver-adapter gem. Be sure to install the same version of your Rails framework. You have more info about it here.

c:\>gem install activerecord-sqlserver-adapter --version=2.3.5

(4) Create an ODBC data source. If you’re running a 64 bit Windows System, don’t use the ODBC Administrator Tool from the Control Panel because a 64 bit ODBC data source won’t work. Instead, open the 32 bit ODBC Administrator Tool this way:

c:\>cd C:\Windows\SysWoW64
c:\>odbcad32.exe

Select a default database on your DSN. Select English as the default language, although you’re not using English (I had problems with date formats using Spanish).

(5) Edit the config/database.yml configuration file:

production:
adapter: sqlserver
mode: ODBC
dsn: your-odbc-data-source-name
host: your-sql-server-host
 username: an-sql-username
password: the-username-password

Ok, it’s time to create your database:

rake db:migrate RAILS_ENV=production

That’s it. Well, almost. If you have any problems with Decimal numbers (I had) just change the decimal type to float on your migration files, and recreate your database.

Apr 12, 20112 notes
#RoR #Windows #SQL Server
3 habits to boost your productivity → facilethings.com
Apr 11, 20116 notes
#productivity #gtd
Apply perspective to GTD → facilethings.com

To understand why priorities are not important in GTD you need to know the role of perspective.

Apr 04, 20110 notes
#gtd #productivity
Making wicked_pdf work on Windows

This week I’ve had to install on a Windows server (specifically Windows Server 2008 R2) a Ruby on Rails app that worked properly on Mac and Linux environments. Of course, I had to make a few tweaks here and there to make it work. Some of them were in the wicked_pdf plugin, which I use to generate PDF files from HTML content.

1) First of all, you have to download the proper wkhtmltopdf executable. This is the engine used by wicked_pdf to create the PDF file. Once installed, you must add an initializer file (config/initializers/wicked_pdf.rb) to show the plugin where to find it. If it’s in a bin folder in our app directory, it would be as follows:

WICKED_PDF = {
  :exe_path => Rails.root.join('bin', 'wkhtmltopdf.exe').to_s
}

2) You need to install a spefic popen3 gem to make it work on Windows:

C:\>gem install win32-open3

And edit the lib/wicked_pdf.rb to use it:

require 'win32/open3'    # instead of require 'open3'

Also remove the -q option on line 19:

command_for_stdin_stdout = "#{@exe_path} #{options} - -"

3) Now it works, but probably you can’t open the PDF files due to a format error. Just add a “b” parameter on line 21 of lib/wicked_pdf.rb. This will turn on binary data mode:

Open3.popen3(command_for_stdin_stdout, "b") do |stdin, stdout, stderr|

4) Now it works and you should be able to open the PDF files. But if you’re using images, they may not appear. This helper should do the trick on Windows systems:

def pdf_image_tag(image, options = {})
  options[:src] = File.expand_path(RAILS_ROOT) + '/public/images/' + image
  tag(:img, options)
end

Use it on your pdf.rb files instead of image_tag.

Apr 01, 20113 notes
#rails #RoR #Windows #pdf
Next page →
2012 2013
  • January 7
  • February 5
  • March 6
  • April 7
  • May 9
  • June 5
  • July
  • August
  • September
  • October
  • November
  • December
2011 2012 2013
  • January 7
  • February 5
  • March 6
  • April 6
  • May 8
  • June 5
  • July 6
  • August 7
  • September 8
  • October 9
  • November 7
  • December 6
2010 2011 2012
  • January 9
  • February 9
  • March 7
  • April 9
  • May 8
  • June 10
  • July 7
  • August 10
  • September 8
  • October 9
  • November 8
  • December 6
2010 2011
  • January
  • February
  • March
  • April
  • May
  • June
  • July 4
  • August 8
  • September 9
  • October 3
  • November 6
  • December 9