Today I finally updated to mod_rails. The install was easy. I was missing a few requirements however the install process told me in exact terms what I needed to do. After rerunning the install everything worked. The mod_rails install process seemed almost too easy.
For those not in the know mod_rails handles everything you need to bring your rails app to production. All you have to do now is plonk your app on a server set up the database. Mod_rails does the rest. Mod_rails also removes the need for a mongrel cluster thus reducing the amount of memory used by the server. Very handy for users such as my self running on small hosting slices. The configuration is also much easier. I reduced a 36 line configuration file down to 4 lines. The only regret I have about mod_rails is that it renders my post on setting up a mongrel cluster with proxy balancer useless. Mod_rails … it just works. That is all.
Check out mod_rails when you get a chance.
I am currently building an app that has a tabbed interface. To my surprise I realized that I have never had to code a tabbed application before. I wanted an easy way to add tabs to my rails application. I used a helper method to identify what the currently selected tab is and add an active class to it.
def link_with_active(text, url)
link = link_to text, url
if request.request_uri == url
return '<li class="active">' + link + '</li>'
else
return '<li>' + link + '</li>'
end
end
Basically this method is an if statement that adds the active class to the li item. Since I would almost always build a tabbed list with an li I thought it was a safe assumption to build this in to the method. Then I just call the helper method from my view. Like so.
<ul>
<%= link_with_active "Home", "/" %>
<%= link_with_active "New Invoice", new_invoice_path %>
</ul>
To be honest I am not totally sure if this is the best way to do this. If anyone has a better way of doing so please comment.