RWVHP

geeky initals

AccessibleFormBuilder has just been pushed out the door.

UPDATE This is the example ;)
  <% a_form_for :user, :url => users_path, :legend => "Login Details" do |f| %>
    <%= f.text_field :login, :label => "Username", :note => "This is visible to other users", :required => true %>
    <%= f.password_field :password, :label => "Password", :required => true %>
    <%= f.password_field :password_confirmation, :label => "Confirm Password", :required => true %>
    <%= f.separator "Personal Details" %>
    <%= f.text_field :firstname, :label => "First name", :required => true %>
    <%= f.text_field :lastname, :label => "Last name", :required => true %>
    <%= f.text_field :email, :label => "E-Mail", :required => true %>
    <%= f.separator "Location Details" %>
    <%= f.text_field :address, :label => "Location", :note => "(eg. New York, 90210, SE1 3SR)", :required => true %>
    <%= f.submit "Sign up" %>
  <% end %>

UPDATE Added HTML output

<form action="/users" class="aFrm" method="post"><div style="margin:0;padding:0"><input name="authenticity_token" type="hidden" value="e39d055ff60d1b5388fcf9864ffd1fa568160b9a" /></div><fieldset><legend>Login Details</legend><ol>
  <li><label for="user_login">Username:</label><input id="user_login" name="user[login]" size="30" type="text" /><span class="requiredField">*</span><em> This is visible to other users</em></li>
  <li><label for="user_password">Password:</label><input id="user_password" name="user[password]" size="30" type="password" /><span class="requiredField">*</span></li>

  <li><label for="user_password_confirmation">Confirm Password:</label><input id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password" /><span class="requiredField">*</span></li>
      </ol>
  </fieldset>
  <fieldset><legend>Personal Details</legend>
    <ol>

  <li><label for="user_firstname">First name:</label><input id="user_firstname" name="user[firstname]" size="30" type="text" /><span class="requiredField">*</span></li>

  <li><label for="user_lastname">Last name:</label><input id="user_lastname" name="user[lastname]" size="30" type="text" /><span class="requiredField">*</span></li>
  <li><label for="user_email">E-Mail:</label><input id="user_email" name="user[email]" size="30" type="text" /><span class="requiredField">*</span></li>
      </ol>
  </fieldset>
  <fieldset><legend>Location Details</legend>
    <ol>

  <li><label for="user_address">Location:</label><input id="user_address" name="user[address]" size="30" type="text" /><span class="requiredField">*</span><em> (eg. New York, 90210, SE1 3SR)</em></li>
  <li><input name="commit" type="submit" value="Sign up" /></li>
</ol></fieldset></form>
Install with
git clone git://github.com/shift/accessible_form_builder.git vendor/plugins/accessible_form_builder

Apache 2.2 + Mongrel

March 7th, 2007

This isn’t so much a blog post as somewhere convenient to put some information for ncl.rb.

My Apache 2.2 + modproxybalancer virtualhost config

<VirtualHost *:80>
  ServerName yourapp.com
  DocumentRoot /home/web/yourapp.com/current/public/
  <Directory "/home/web/yourapp.com/current/public">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>
  # Configure the cluster member proxy
  <Proxy balancer://your_app_cluster>
    BalancerMember http://127.0.0.1:3000
    BalancerMember http://127.0.0.1:3001
    BalancerMember http://127.0.0.1:3002
    BalancerMember http://127.0.0.1:3003
  </Proxy>
  RewriteEngine On
  # If there is a maintenence.html file in your
  # public dir all requests will get rerouted to
  # this file.  This is for use with capistrano
  RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
  RewriteRule ^.*$ /maintenance.html [L]

  # Rewrite index to check for static index.html
  RewriteRule ^/$ /index.html [QSA]

  # Rewrite to check for Rails cached pages with .html extentions
  RewriteRule ^([^.]+)$ $1.html [QSA]

  # All dynamic requests get sent to the cluster
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://your_app_cluster%{REQUEST_URI} [P,QSA,L]

  # Deflate for clients that support it.
  AddOutputFilterByType DEFLATE text/html text/plain text/xml
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

  # Error and access logs.
  ErrorLog /var/log/apache/app_error.log
  CustomLog /var/log/apache/app_access.log combined
</VirtualHost>

Now if you take the above example it’ll send all requests to your pack of mongrels, but say you want to have more then one application running on your domain (say beast).

You’ll need to create another proxy balancer
  <Proxy balancer://your_second_app_cluster>
    BalancerMember http://127.0.0.1:3004
    BalancerMember http://127.0.0.1:3005
    BalancerMember http://127.0.0.1:3006
    BalancerMember http://127.0.0.1:3007
  </Proxy>
And then add the RewriteRule for it
RewriteRule ^/forums/(.*)$ balancer://your_second_app_cluster%{REQUEST_URI} [P,QSA,L]
Now anything going to / that isn’t /forums/.* will goto yourappcluster and anything with /forums/.* will goto yoursecondapp_cluster
<VirtualHost *:80>
  ServerName yourapp.com
  DocumentRoot /home/web/yourapp.com/current/public/
  <Directory "/home/web/yourapp.com/current/public">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>
  # Configure the cluster member proxy
  <Proxy balancer://your_app_cluster>
    BalancerMember http://127.0.0.1:3000
    BalancerMember http://127.0.0.1:3001
    BalancerMember http://127.0.0.1:3002
    BalancerMember http://127.0.0.1:3003
  </Proxy>
  <Proxy balancer://your_second_app_cluster>
    BalancerMember http://127.0.0.1:3004
    BalancerMember http://127.0.0.1:3005
    BalancerMember http://127.0.0.1:3006
    BalancerMember http://127.0.0.1:3007
  </Proxy>

  RewriteEngine On
  # If there is a maintenence.html file in your
  # public dir all requests will get rerouted to
  # this file.  This is for use with capistrano
  RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
  RewriteRule ^.*$ /maintenance.html [L]

  # Rewrite index to check for static index.html
  RewriteRule ^/$ /index.html [QSA]

  # Rewrite to check for Rails cached pages with .html extentions
  RewriteRule ^([^.]+)$ $1.html [QSA]

  # All dynamic requests get sent to the cluster
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/forums/(.*)$ balancer://your_second_app_cluster%{REQUEST_URI} [P,QSA,L]
  RewriteRule ^/(.*)$ balancer://your_app_cluster%{REQUEST_URI} [P,QSA,L]

  # Deflate for clients that support it.
  AddOutputFilterByType DEFLATE text/html text/plain text/xml
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

  # Error and access logs.
  ErrorLog /var/log/apache/app_error.log
  CustomLog /var/log/apache/app_access.log combined
</VirtualHost>
yourappcluster mongrel_cluster.yml
---
port: "3000" 
environment: production
address: 127.0.0.1
pid_file: log/mongrel.pid
servers: 4

yoursecondappcluster mongrelcluster.yml

---
port: "3004" 
environment: production
address: 127.0.0.1
pid_file: log/mongrel.pid
servers: 4

Hope that made sense, as its off the top of the head apart from the base apache 2.2 vhost config

UPDATE If your running a Rails app under a path remember to set

ActionController::AbstractRequest.relative_url_root = '/path'

In your environment.rb or your links will be wrong

About RWVHP

Photo of Vincent Palmer the site owner.

Vincent is a self-confessed geek, who's day job is as a Rails developer, outside of work he likes to play with home automation gadgets. He resides in Newcastle upon Tyne.

Page Sections

Copyright © 2008 Vincent Palmer