Tag Archives: rails

Recursive custom to_json in Ruby for arrays of objects or nested objects

Let’s say we want to customize the json template for an object: class User def to_json super(:except => [:password, :password_salt, :encrypted_password, :last_sign_in_ip, :updated_at, :current_sign_in_ip, :remember_token, :reset_password_token, :remember_created_at]) end end Apparently this is fixed in Ruby 1.9 but for now only converting an object [...]
Posted in Software | Also tagged , , , , | Comments closed

Getting FancyUpload to work with Rails

FancyUpload is a slick looking file uploader with a progress bar. However, it’s not completely obvious how to get it working with your Rails application. I searched long and hard and found 2 pretty good examples here and here. The problem is that the former only works with Amazon S3, and the [...]
Posted in Software | Also tagged , , , , | Comments closed

Converting Table Data to YAML for Testing in Ruby on Rails

One of my clients has a huge application with no test suite. I am helping the company migrate to Rails 2.3 as well as remove some bottlenecks from their code. I needed to convert around 10 look-up tables to YAML’s so that I could load the data as fixtures and test the application [...]
Posted in Software | Also tagged , , , , , , | Comments closed

Back links for your Ruby on Rails application

Here is a nice little helper I wrote to display back links: def back_link link_to "« Go Back", request.env["HTTP_REFERER"].blank? ? "/" : request.env["HTTP_REFERER"] end If you just use the HTTP_REFERER without checking if it’s blank, weird things can happen if someone lands on your page from an email, for example. If you enjoyed this post, make [...]
Posted in Software | Also tagged , | Comments closed

Logging your Rails model (the easy way)

In one of my Rails applications, I have some pretty heavy tasks in my models. I decided to log to different files for two of my models so that I can easily make sure these tasks are performed correctly without going through my application log. I also call some of my model methods [...]
Posted in Software | Also tagged , , , | Comments closed

Defending Against Attacks With Rails

A couple weeks ago I presented on Rails security at a local Ruby On Rails meetup. I finally got around to posting the slides online. The presentation covers topics including authentication, hashing, salting, key stretching, white listing, session hijacking, replay attacks, session fixation, cross-site request forgery, cross site scripting, sql injections, other injections, and some [...]
Posted in Software | Also tagged , , , , , , , , , , | Comments closed

Simple Time Select for Ruby On Rails Just Got Simpler

I added a start_hour and end_hour feature to my simple time select. Here are the details from the README: Simple time select also takes a start_hour and end_hour option to be specified in military format (between 0-23). <%= time_select "event", "time", { :default => Time.now.change(:hour => 21), :simple_time_select => true, :minute_interval => 20, :time_separator => "", [...]
Posted in Software | Also tagged , , | Comments closed

The best time_select plugin for Ruby On Rails!

In some cases, the Ruby on Rails time_select helper is much uglier than it needs to be. It spits out 3 select boxes for the hour, minutes, and seconds. Your users do not always need accuracy to the minute. For example, you do not schedule doctor’s appointments for 3:13PM. You would at least [...]
Posted in Software | Also tagged , , , , | Comments closed