How to get rails authentication and redirection to work under RJS
Posted on September 30, 2006
Leave a Comment
While adding some new features to the auth system I came across some issues regarding certain RJS links that weren’t working as planned in regards to the authentication. With the RJS links, when clicked, if the auth session was expired it wouldn’t redirect back to the login page.
I’m using Auth Generator 2.0 and this might not apply to your auth system. So for redirection you’ll have to look beyond the standard rails redirect_to() method. This is because the prototype library doesn’t respond to HTTP status codes like a browser does. It also doesn’t follow 3xx redirect status codes.
Good thing the JavascriptGenerator in RJS has a redirect_to() method to take care of this. So for RJS methods or RJS links in views that require authentication redirection, you’ll need to call a separate auth method for the RJS methods in your controller.
The original auth method would look something like this:
def check_authunless user_logged_in?
flash[:notice] = “You lack credentials to access this page”
redirect_to :controller => ‘auth’, :action => ‘login’
end
end
But this won’t work in an RJS call. So you’ll have create something like this:
def rjs_check_authunless user_logged_in?
flash[:notice] = “Sorry but your session has expired, please login again.”
render :update do |page|
page.redirect_to :controller => ‘auth’, :action => ‘login’
end
return false
end
end
Set this to run in your RJS methods in order to force a redirect if their login has expired.
def rjs_method
rjs_check_auth
… rest of RJS code …
end
or stick it in a before_filter in your controller. I’m sure there a million other ways to do this and probably a few thousand better but this works for me.
.
Posted on September 30, 2006
Filed Under Daily Thoughts, Design, Ruby on Rails, Tech, Web
Rails Capistrano 1.2.0 Cheetsheet PDF
Posted on September 30, 2006
Leave a Comment
Just ran across this and its pretty complete. I’m not a Capistrano expert but this has served as a pretty good reference so far, so much more to learn with this new release though.
Get the Capistrano 1.2 Cheefsheet here
.
Posted on September 30, 2006
Filed Under Daily Thoughts, Hosting, Ruby on Rails, Tech, Web
Don’t Let this be You
Posted on September 28, 2006
Leave a Comment

A little bit of funny for the day. Don’t let this be you, no puking on websites.
.
Posted on September 28, 2006
Filed Under CSS/XHTML, Daily Thoughts, Design, Entertainment, Tech, Web
Engineyard.com Launches - Reliable, Easily Managed, Instantly Scalable Rails Hosting
Posted on September 25, 2006
3 Comments
![]()
Engineyard.com launched yesterday and it looks really awesome. From the website:
“The first Ruby on Rails application deployment service that combines reliability, ease of use, and scalability.”
They have engineered a superb network of hardware and software to provide an easy, reliable and scalable Ruby on Rails solutions. From a glance these guys have also set this up on a rock-solid infrastructure and on some great hardware/software.
I believe they are using finely tuned and customized Gentoo Linux images and ( to start ) a 6TB SAN storage solution along with fault-tolerant, redundant and high-availability Web, Email, DNS and DB servers. And get this, because of the 6TB SAN, their Dual, Dual-Core Opteron servers don’t have hard-drives, just 128MB ATA flash cards.
I’m the type that would LOVE to just a week or weekend setting this type of system up myself, but I can definitely see the value in saving time for others who don’t have the time or resources to really do this themselves. Who knows, I’m even considering this as a deployment solution for SugarStats when we launch.
“Your applications benefit from redundant and load balanced web, application, database, and mail servers. Redundant SAN storage safeguards your data and clusterizes your application with no code changes.”
Sweet…
Here is a map of their Physical Application Cluster
Here is a map of their Logical Application Cluster
Ezra ( One of the Rails deployment specialists to build Engineyard ) has just put up a post describing the technical layout and technology stack of Engineyard
They’ve setup the system to be very easy to use and have it so any deployed app/account can be managed, up/downgraded and setup via a simple web based interface. When signing up you get “slices” of the Engineyard service. It is best described like this:
“Engine Yard cluster capacity is purchased by the slice. When you buy a slice, you get a VPS dedicated to your application, PLUS you get a proportional part of the cluster’s resources, which include multiple database servers, web servers, mail servers, load balancers, etc.”
“You arrange slices into environments. A typical customer may have 1 slice for their Staging environment, plus 2-4 slices for their Production environment. When you get more than 1 slice for a given environment, the system ensures that those slices are on different physical hardware, another way we offer high reliability for your applications.”
“The reason to get more than 2 slices for a given environment is one of capacity. If you have a site that gets a lot of traffic, you may need more Production slices. If your business has seasonal peaks, or gets Dugg or Slashdotted, you can buy more slices precisely when you need them. It’s instant scalability, which allows you to grow with your needs and pay as you go.”
The pricing starts at $249 per slice ( plus a $199 setup fee ) but they are having a special 90 day sign-up promotion where you can get them for $149 ( plus a $99 setup fee ). Also the price per slice gets cheaper as the volume of slices purchased increases.
All in all this is looking like a really great, solid and reliable service. I would recommend going over to Engineyard.com and checking them out if you’re launching a Ruby on Rails app anytime soon.
.
Posted on September 25, 2006
Filed Under Business, Daily Thoughts, Hardware, Hosting, Productivity, Ruby on Rails, SEO, Startup, Tech, Web
MySQL Query Analyzer Rails Plugin Released
Posted on September 22, 2006
Leave a Comment

Bob Silva has released a fine MySQL Query Analyzer plugin for Rails. I’ve been looking for something like this for a while, I’m going to give it a shot and see how well it works. Check it out.
“With all that said, I wrote a plugin to make it easier to catch those mistakes and stay on top of your database optimizations. This plugin makes use of the EXPLAIN sql statement in MySQL to print out how MySQL formed its execution plan. Basically, for each SELECT query your application runs in the development or testing environments, Rails will also print the query execution plan right after it so you can quickly analyze the queries Rails is making and either add indexes, reorder your joins and remove unneeded or redundant indexes.”
.
Posted on September 22, 2006
Filed Under Analytics, Daily Thoughts, Ruby on Rails, Tech, Web

