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
The Mephisto team has recently released 0.8 on the way to one point-oh adding
Along with more, checkout the change log from git
git clone git://activereload.net/mephisto.git mephisto cd mephisto; less CHANGELOG
Happy Blogging.
Mojo is now in a public beta, if your reading this there is a 99% probability that your in the Ruby world so if you want to get started wreaking havoc at work making all of the phones ring you can
gem install mojo
Congrats to the guys at Mojo for a great job.
The following is just to claim the blog on its new URL with Technorati by linking to my Technorati Profile
Avahi/Zeroconf or Rendezvous as your Mac would know it, can be used in published DNS records (unicast) as well as the normal LAN type setup (multicast), its already a standard why don’t we use this for discovering RESTful resources?
All this would require would be a service type registered eg. rest.tcp and a flag in the TXT record naming your resources eg. “resources=/users /articles /articles/comments”.
I brought this up (quite randomly) during a talk at my local Ruby Group (ncl.rb).
Gimme your feedback?
UPDATE Forgot to add from the initial post use the :resource/new to get an empty object (to_xml or whatever)
An example of discovering unicast Zeroconf services isshift@carbon:~# avahi-browse -a -d 0pointer.de + n/a n/a Lennart’s Blog _http-rss._tcp 0pointer.de + n/a n/a tango SSH Remote Terminal 0pointer.de + n/a n/a dt115 SSH Remote Terminal 0pointer.de + n/a n/a ring2 SSH Remote Terminal 0pointer.de + n/a n/a PulseAudio Web Site Web Site 0pointer.de + n/a n/a Avahi Web Site Web Site 0pointer.de + n/a n/a Lennart's Blog Web Site 0pointer.de + n/a n/a Lennart's Photos Web Site 0pointer.de + n/a n/a Lennart's Homepage Web Site 0pointer.de
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
The if statement, sometimes you don’t want to type
if user.password == user.username
# do something
end
Sometimes you might just want to simply check that the value set isn’t nil
user.password ||= 'default_password'
Thats the same as writing
if user.password == nil
user.password = 'default_password'
end
A slight variation of that would be
user.password = params[:password] || 'default_password'
Which would be the same as
if params[:password] != nil
user.password = params[:password]
else
user.password = 'default_password'
end
Theres probably more ways of doing things like this that I haven’t came across yet, if you know of others leave a comment.
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.