BUILDING A SOCIAL NETWORKING
WEBSITE WITH RUBY ON RAILS

Overwriting default thumbnails

Posted 3 months ago by Michael Hartl

Just a quick note: once you get to Chapter 12 on Avatars, you should add the following validation to the User model:

class User < ActiveRecord::Base
  .
  .
  .

  def validate
    # Protect against overwriting default thumbnail...
    if %w(default_thumbnail default).include?(screen_name)
      errors.add(:screen_name, "cannot be that, nice try though")
    end
  end
  .
  .
  .
end

Without this validation, users called ‘default’ and ‘default_thumbnail’ can both overwrite the default thumbnail in the avatar image directory. D’oh! Thanks to Rohit Koul for pointing it out.

Comments

There are 0 comments on this post. Post yours →

Post a comment

Required fields in bold.