1
2
3
4
class AccountsController < ApplicationController

  layout 'application'
...

Ruby Password update code

by danielharan, July 16, 2008 16:59, 4 refactorings, tagged with rails, restful, authentication

Mostly straight from a tuto...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
def all_shops(products)
    products.collect { |product| product.shops }.flatten.uniq
end

Ruby On Squash a collection.

by danielharan, July 06, 2008 03:31 Star_fullStar_fullStar_fullStar_fullStar_full
880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
def email
  return '' unless logged_in?
  current_user.email
...

Ruby On if else if else

by danielharan, June 17, 2008 13:50

You could put those in a he...

880cbab435f00197613c9cc2065b4f5a Talk

Ruby On collecting attributes from ...

by danielharan, June 17, 2008 13:47

While Fabien's solution doe...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
def get_number_sequence(number)
  @sequence = %w{ 24142 15151 25232 25252 14251 23252 23242 25151 24242 24252 }[number]
  ...
...

Ruby On Looking for comments on sty...

by danielharan, June 16, 2008 15:13 Star_fullStar_fullStar_fullStar_full

Can you link to information...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
<% if @user.carrier? %>
  <li style="width:190px" id="mobile_no_div">
    <%= @user.carrier.name %> &nbsp; <%= @user.mobile_no %>
...

Ruby On RHTML Refactoring

by danielharan, June 12, 2008 15:47 Star_fullStar_fullStar_fullStar_full

having carrier_id == 0 in t...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
def find_npa(dialed_nxx)
  return 819 if [ 205, 208, 210, 213, 243 ].include? dialed_nxx
  return 613 if [ 203, 204, 212, 216, 218 ].include? dialed_nxx
...

Ruby On Array iteration

by danielharan, June 12, 2008 00:02 Star_fullStar_fullStar_fullStar_full
880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
>> start = Time.at 0
=> Wed Dec 31 19:00:00 -0500 1969
>> later = start + 60 * 60 * 2 + 60 * 3 + 1 # add 2 hours, 3 minutes and 1 second
...

Ruby On time to second, second to time

by danielharan, June 11, 2008 21:44 Star_fullStar_fullStar_fullStar_full

Why not just use Time ?

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
# why does the alphabet include '*' anyways?
(('a'..'z').to_a << '*').each do |letter|
  `curl|request somesite.com/search?q=#{letter} to /tmp/cache/searches/#{letter}`
...

Ruby On Can this scraper be simplif...

by danielharan, May 31, 2008 17:27

You're mixing too many conc...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
  # Find all articles in the given date range based on the published_at field
  def self.find_archived(year, month=nil)
    if month.nil?
...

Ruby On Building a dynamic date range

by danielharan, May 09, 2008 00:53 Star_fullStar_fullStar_fullStar_fullStar_full

This version is a bit longe...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
class Poll
  attr_accessor :question
  def initialize(question, answers=[])
...

Ruby On Rubyize this : 6th edition

by danielharan, May 04, 2008 00:11 Star_fullStar_fullStar_fullStar_fullStar_full

System is a vile word in a ...

880cbab435f00197613c9cc2065b4f5a Talk

Ruby On Step-REST uuuuugly controller

by danielharan, April 28, 2008 21:01 Star_fullStar_fullStar_fullStar_fullStar_full

That's no longer really res...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
class JobBoard < ActiveRecord::Base
  has_many :job_board_postings
  
...

Ruby Ruby has_finder on has_many ?

by danielharan, April 01, 2008 16:10, 1 refactoring, tagged with has_finder rails

This smells... one of the m...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
def fizz!
   'fizz'
end
...

Ruby On Challenge: Ugliest Ruby Fiz...

by danielharan, December 21, 2007 15:53 Star_fullStar_fullStar_fullStar_full

No way can I compete with M...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
module Wasabi
  module Fizzy
    def fizzy?
...

Ruby On Challenge: Ugliest Ruby Fiz...

by danielharan, December 20, 2007 22:18 Star_fullStar_fullStar_full

I was inspired by http://re...

880cbab435f00197613c9cc2065b4f5a Talk

C# On Code to Simplify

by danielharan, December 19, 2007 18:19 Star_fullStar_fullStar_fullStar_full

That code is an abomination...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
  create do
    before { @post.user = current_user }
    responds_to :html, :js do |format|
...

Ruby On resource_controller: Redesi...

by danielharan, November 06, 2007 01:02

I prefer responds_to. Since...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
class String 
  def postal_code?  
    self.strip =~ /^[a-z]\d[a-z][ -]?\d[a-z]\d$/i
...

Ruby On Is This String Postal?

by danielharan, October 30, 2007 16:08 Star_fullStar_fullStar_fullStar_full

Now that I'm looking at tha...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
class String 
  def postal?  
    self =~ /[a-zA-Z]{1}\d{1}[a-zA-Z]{1}([\x20-])*\d{1}[a-zA-Z]{1}\d{1}/
...

Ruby On Is This String Postal?

by danielharan, October 30, 2007 15:40

That ternary operator is no...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
namespace :migrations do
  
  desc 'reverts, renames and re-executes uncommitted migrations that conflict with already committed migrations'
...

Ruby Rails migration conflict re...

by danielharan, October 26, 2007 18:25, 1 refactoring, tagged with rails

Explained here: http://www....

880cbab435f00197613c9cc2065b4f5a Talk

Ruby On Integer puzzle

by danielharan, October 18, 2007 14:30

Cool, I'm looking forward t...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
require 'erb'
class ClientMigrator
  def self.create(fields)
...

Ruby Dynamic migrations for rails

by danielharan, October 12, 2007 04:27, 1 refactoring

How do you create a rails p...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
if self.location_type.to_s == 'point'
  breaker = {'fr' => 'proximite', 'en' =>'near' }[self.lang]
else  
...

Ruby On Iffy

by danielharan, October 11, 2007 19:37 Star_fullStar_fullStar_full

Assuming you are only worki...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
def remove_insults(input)
  %w{ stupid moron dumbass retard }.each {|insult| input.gsub!(Regexp.new(insult, true),'*' * insult.length) }
  input
...

Ruby On Rubyize this : 3rd edition

by danielharan, October 11, 2007 18:38 Star_fullStar_fullStar_full

After noticing the issue wi...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
class ITA
  
  class Number
...

Ruby On Integer puzzle

by danielharan, October 03, 2007 16:31 Star_fullStar_fullStar_fullStar_fullStar_full

Here is the full solution, ...

880cbab435f00197613c9cc2065b4f5a Talk