https for rails 1
Heres some tips for rails https.
First – use the plugin SslRequirement. But REMEMBER this ONLY works on controllers that are listed in the routes.rb file as RESOURCES
map.resources :blahblah
IE they only work on resources. Period. For non resource controllers, you will have to stick it in the links.
<%= button_to "Checkout", {:action => :checkout,:controller=>"catalog",:protocol=>"https://",:only_path=>false },{}%>
Here is how to use the ssl plugin
ruby script/plugin install ssl_requirement
class ApplicationController < ActiveRecord::Base
include SslRequirement
end
class AccountController < ApplicationController
ssl_required :signup, :payment
ssl_allowed :index
def signup
# Non-SSL access will be redirected to SSL
end
def payment
# Non-SSL access will be redirected to SSL
end
def index
# This action will work either with or without SSL
end
def other
# SSL access will be redirected to non-SSL
end
end
Next Here is a working apache / mongrel config for a https ssl virtualhost. REMEMBER enable proxy, rewrite, and headers in the apache modules stanza
<IfDefine SSL>
<IfDefine !NOSSL>
<VirtualHost 192.168.1.42:443>
DocumentRoot /srv/www/site-name/current/public
ServerName www.site-name.com:443
ServerAdmin webmaster@site-name.com
ErrorLog /var/log/apache2/site-name.com-error_log
CustomLog /var/log/apache2/site-name.com-access_log combined
HostnameLookups Off
UseCanonicalName Off
ServerSignature Off
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /etc/apache2/site-name-ssl/www.site-name.com.crt
SSLCertificateKeyFile /etc/apache2/site-name-ssl/site-name.key
SSLCertificateChainFile /etc/apache2/site-name-ssl/gd_intermediate_bundle.crt
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
<Directory "/srv/www/site-name/current/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
RewriteEngine On
# Don't do forward proxying
ProxyRequests Off
# Enable reverse proxying
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
RequestHeader set X_FORWARDED_PROTO 'https'
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
RewriteRule ^/$ /index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule .* http://127.0.0.1:3000%{REQUEST_URI} [L,P,QSA]
# Deflate
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/xml application/xhtml+xml text/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</VirtualHost>
</IfDefine>
</IfDefine>
My pain is your gain.
SVN externals
Here is how to set a directory to fetch as an svn:externals directory. I keep forgetting this. Now you can remember it too.
#make sure your editor variable is set, find the editor
# or which vi or whatever
which emacs
#no spaces in EDITOR="
export EDITOR="/usr/bin/emacs"
cd THE-DIRECTORY-YOU-WANT-EXTERNAL-TO-BE-IN
#propset the svn externals on the current directory, this pops up the editor
svn propedit svn:externals .
# in emacs --- in emacs -- in emacs one directory per line.
apache-ant http://svn.repository.my/apache-ant/trunk/
# you saved the file, back in the shell
#download the repo as the new directory directory-name, in this case apache-ant
svn update
DONE
Send HUGE files from rails
I had to send large files with rails, so huge that it was killing rails.
Here is the solution, note the allow-x-send-file NOT allow-x-sendfile, this wasted a few hours of mine.
Make sure that “mod_fastcgi” is in the server.modules stanza of the lighttpd.conf file
Here is the vhosts.conf file
$HTTP["host"] =~ "www.yoursite.com" {
server.document-root = base + "/domains/yoursite.com/web/public/"
server.error-handler-404 = "/dispatch.fcgi"
compress.filetype = ( "text/plain", "text/html", "text/css", "text/javascript" )
compress.cache-dir = base + "/domains/yoursite.com/web/tmp/cache"
fastcgi.server = ( ".fcgi" =>
( "localhost" =>
( "socket" => base + "/var/run/yoursite-0.socket",
"allow-x-send-file" => "enable",
"bin-environment" => ("RAILS_ENV" => "production")
)
)
)
}
rails controller code
def send_this_file
# this will force rails to read the entire file then stream it out BAD
#send_file "#{RAILS_ROOT}/public/pdf/#{params[:id]}" , :type => mime_for(params[:id]), :disposition => 'inline', :stream => false
# this will pass the headers to lighttpd and force it to handle the large static file, rails doesn't read the large file.
filename = "#{RAILS_ROOT}/public/pdf/#{params[:id]}"
response.headers['Content-Type'] = "application/force-download"
response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\""
response.headers["X-LIGHTTPD-send-file"] = filename
response.headers['Content-length'] = File.size(filename)
render :nothing => true
end
Active Resource on OSX
I am making a site which uses an object datastore cache and rails. The only feasable way of getting data to rails is via XML. The simplest way is to use ActiveResource , which is still way way beta.
Here’s how I did it.
from http://reprocessed.org/blog/archives/2006/08/01/active_resource_on_edge.html
You may be tempted to use edge rails
rake rails:freeze:edge
This won’t work, ActiveResource is not included in Edge, only Trunk. Here is how to set up a rails instance that uses ActiveResource.
mkdir -p some_name/vendor; cd some_name
svn co http://dev.rubyonrails.org/svn/rails/trunk vendor/rails
rails .
Then, add this line to your config/environment.rb file, somewhere inside the Rails::Initializer.run do |config| block:
config.load_paths += %W( #{RAILS_ROOT}/vendor/rails/activeresource/lib )
You are running on trunk now, this is the latest version of rails, and may be flakey.
Here is how to use it
From http://weblog.techno-weenie.net/2006/12/13/taking-ares-out-for-a-test-drive
I created two rails sites on my local machine, one is the server. One is the client. ActiveResource needs to be on the client. On the server I made a RESTful site which hooked up to MySQL
Here is the Migration for the database.
class CreateParts < ActiveRecord::Migration
def self.up
create_table :parts do |t|
t.column :date, :date
t.column :customer, :string
t.column :customer_part_number, :string
t.column :manufacturer, :string
t.column :factory_part_number, :string
t.column :description, :string
t.column :cost, :string
t.column :selling_price, :string
t.column :notes, :text
end
end
def self.down
drop_table :parts
end
end
This command generates the restful scaffolding to view the data.
ruby script/generate scaffold_resource part date:date customer:string customer_part_number:string manufacturer:string factory_part_number:string description:string cost:string selling_price:string notes:text
Then on the client site I did the same. Except there is no database, just the previous classes.
In the Models section on the client, use this as your model for the part
class PartResource < ActiveResource::Base
self.site = 'http://localhost:3000'
# site.user = 'username'
# site.password = 'secret_sauce'
end
class Part < PartResource
end
When I started each server up on a different port, the client can query the server and the server queries the database.
script/server lighttpd -p3000 # server
script/server lighttpd -p3001 # client
Pull up a page at http://localhost:3001/parts/1000 and check it out.
Enjoy
urpmi note to self
I had to update the repository on a linux server to use local copies of cd’s I made
first remove the old repos rpm.removemedia -a
then add the new ones
urpmi.addmedia "linux1" file://home/linux/2006/media/main with_hdlist ../media_info/hdlist1.cz
urpmi.addmedia "linux2" file://home/linux/2006/media/applications with_hdlist: ../media_info/hdlist2.cz
urpmi.addmedia "linux3" file://home/linux/2006/media/modules with_hdlist: ../media_info/hdlist3.cz
urpmi.addmedia "linux4" file://home/linux/2006/media/dkms with_hdlist: ../media_info/hdlist4.cz
urpmi.addmedia "linux5" file://home/linux/2006/media/firmwares with_hdlist: ../media_info/hdlist5.cz
urpmi.addmedia "linux6" file://home/linux/2006/media/contrib with_hdlist: ../media_info/hdlist6.cz
then install my file urpmi -i apache-mod_proxy
Setting up fastcgi and lighttpd in Fedora Core 5
Don’t install the fcgi gem. If you did, run:
gem uninstall fcgi
Install FastCGI
wget http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure
make
sudo make install
Go to the homepage http://raa.ruby-lang.org/project/fcgi
Download the tarball read the README and follow the install instructions
wget http://www.moonwolf.com/ruby/archive/ruby-fcgi-0.8.7.tar.gz
ruby install.rb config -- --with-fcgi-include=/usr/local/include --with-fcgi-lib=/usr/local/lib
ruby install.rb setup
ruby install.rb install
Get lighttpd installed
yum install lighttpd-fastcgi
Set your security level
If your were unfortunate enough to install SeLinux ( Security Enhanced ), I feel your pain.
Go to the “Security level and firewall” settings, disable SeLinux
Configure Lighttpd
Go to rails root. Run “script/server lighttpd” it should fail the first time but it generates a
Set lighttpd to start automatically in the “Systems/Services” application
OSX Webdav SVN
Osx can mount a subversion repository over webdav. The repository appears as a network drive. Any changes to files in the repository are autocommited. Cool, except..
The svn repository is filled with one .DS_store file for each directory. Annoying
type this in a terminal window and restart.
defaults write com.apple.desktopservices DSDontWriteNetworkStores true
No more problem.
Backup your MySQL databases and your user folder on your mac with Automator
I have been backing my stuff up weekly using an applescript. But ran into a wall trying to automate the mysql backup. The issue is I have ALOT of development databases and I do not want a single dumpfile, else I would have to blow away and rebuild everything if I needed a refresh of one table. I wrote this nifty automator script.
- 1 Basicly the steps are drag Automator::Run Shell Script.
- 2 Fill in the script.
- 3 Drag Mail::New Message and send confirmation to yourself. I would have preferred to add an event to iCal but there is no Time.now() feature in the iCal Automator actions, so my system would always be backed up freshly August 18th 2006 at 12:50 pm, This is a problem.
- 4 Drag the Mail::Send Outgoing Messages
- 5 Save as a workflow
Here is the script from step one.
It asssumes there is no root password. I never open my laptop up to the world so a password is a hassle.
I created a directory in /Users/joel/backup_mysql/ to hold the archived mysql I created a directory in /Volumes/DROPSHIP/backup to archive to ( This is an external firewire drive )
for x in `/usr/local/mysql/bin/mysql -u root -Bse "show databases"`; do
/usr/local/mysql/bin/mysqldump -u root $x | /sw/bin/gzip -9 > /Users/joel/backup_mysql/$x.gz
done;
/usr/bin/rsync -aE --delete ~ /Volumes/DROPSHIP/backup 2>>~/rsyncErr.txt || echo -n;
To execute, rightclick :: Automator :: Backup Laptop …

Ubuntu kicks Mandrake 1
I just installed a Django site on Ubuntu 64. This will be for an insanely busy hardware review site, I recently set up a mandrake 64 system. This is a totally non-biased, scientific opinion; Ubuntu kicks ass. I’m not looking back.
2006.0 a spacecase oddesy 1
I want to start using Capistano ( a deployment tool for ruby on rails ). Its pretty cool. It executes deployment commands on multiple servers in parallel over ssh.
It needs SVN to work. It says in the instructions that you cannot use file:/// repositories. So I thought hey why not use http://localhost. That brick wall dented my head.
What they meant to say is you cant use local repositories unless you have a static IP.
Capistrano executes the svn command from the other server so localhost is relative to the other server not my nifty laptop.
So I need a remote static ip install of SVN
I need to install subversion my 64 bit dev platform to ease Rails deployments. It ran Mandrake 2005 ( this is one of the first versions that are 64 bit for mandrake ). When I tried to get it running it wanted to install libraries for a newer version of KDE. I was afraid that this would break the current setup, or more over be a P.O.T.A later on. So I figured I should upgrade the OS.
Here is the saga. My dev machine is a gaming AMD64 3000 with 2 gigs of ram and hardware mirrored 200 GB SATA RAID drives
I tried installing mod dav svn for the older version of Apache2 I had installed. Apparently it was the 32 bit version. The only versions of mod dav svn I have are for 64 bit Apache.
Reinstall Apache use newer version.
Impressive speed bump
Install mod dav svn install subversion. required libraries want to overwrite kde_core…. NO WAY.
Time for a full reinstall
- Downloaded Mandriva 2006.0 DVD
1
- installed
- wouldn’t boot, problem with raid array.
2
- install again ( did I do it wrong )
- nope
- broke up raid set formatted each disk indepentantly, computer hung on formatting disk 2
- reboot retry, formatted no problem
This wasn’t the issue
3
- installed again
- 2006.0 raid driver detects if you have raid and tries to set up regardless if hardware raid is already taking care of it
- Downloaded Mandriva 2006.0 Core updates.
- core updates, fixes raid issue
- nvidia driver for 6200 doesn’t work. X won’t boot.
4
- Reinstall Repatch, to try to use a different video card ( inseting the core updates after its installed skips the section to choose video card. )
- choose generic video card.
- patch
- still wont boot
- during boot, the video card driver shown isnt what I installed.
5
- reinstall, choose the generic nvidia card ( the driver not written by nvidia )
- patch, just for kicks verify the generic driver is still selected. It wasn’t
- fixed.
- kde boots. There is no file manager. its worthless.
its getting late ( about 2 am )
6
- reinstall
- repatch
- oops forgot to verify video card
7
- reinstall
- repatch
- oops
8
* So I Reinstalled another … and that stayed up.
this reminds me of this monty python skit
**FATHER**
Listen, lad, I built this kingdom up from nothing.
All I had when I started was swamp ...
Other kings said I was daft to build a castle on a swamp,
but I built it all the same ...
just to show 'em.
It sank into the swamp.
So I built a another one ...
that sank into the swamp.
I built another one ...
That fell over and THEN sank into the swamp ....
So I built another ...
and that stayed up.
... And that's what your gonna get, lad:
the most powerful kingdom in this island.
**PRINCE**
But I don't want any of that, I'd rather ...
**FATHER**
Rather what?
**PRINCE**
I'd rather ... just ... sing ...
MUSIC INTRO
- reinstall
- make same software selections but also choose multimedia computer ( gimp xmms… )
- KDE WORKS
- set up system.
- samba lacks place to enter which workgroup the computer belongs to
- vncserver wont work
- am I connecting correctly?
- wait I dealt with this a while ago during the 2005 installation.
- 64 bit vncserver that ships with mandrake wont work ( don’t know why )
- deleted it, installed the 32 bit version ( works fine )
- install ruby
- install rails
- mysql wont allow tcp connections, I think its getting config information from more than the my.cnf
- install ruby mysql
- installed fcgi
- installed mod_fcgi
- fastcgi works no errors in logfiles.
- tried installing ruby fcgi
- wont work needs fastcgi headers and compiled to 64 bit
- unistalled fastcgi
- compiled from source
- installed ruby fcgi
- works
- printer driver won’t work ( still have to work on this one )
- samba workgroup is incorrect. ( still have to work on this one )
- SVN works.
The sun is coming up
Total time… one weekend. What a waste of time.