1
2
3
4
class Test
  @@tries=0
  attr_reader :num
...

Ruby Code transactions

by John Sietsma, August 20, 2008 07:14, 5 refactorings, tagged with transact, rails

In a Rails controller I'm s...

37ce1520d319fa8095d05aa475951616 Talk
1
2
3
4
class Report < ActiveRecord::Base
  belongs_to :reportable, :polymorphic => true
  
...

Ruby A shorter way to declare cl...

by danielharan, August 14, 2008 19:47, 1 refactoring, tagged with ruby, rails, constants

I added these so I could re...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
if @events != nil
  @events.each do |event|
    if @recurrents != nil
...

Ruby superfluous if statements

by ttdavett.myopenid.com, August 10, 2008 22:51, 4 refactorings, tagged with ruby, rails, if, else

I'm pretty sure theres a be...

F677fa685a2cfe8aff31f161062db3d3 Talk
1
2
3
4
def user_path(path)
  pre = $user_remote_pictures_paths[digest(path, $user_remote_pictures_paths.length)]
  "#{pre}/#{path}"
...

Ruby Same function repeated but ...

by incrediblybuilt.myopenid.com, August 08, 2008 19:00, 5 refactorings, tagged with rails

It's ugly, yes..

Avatar Talk
1
2
3
4
    times.each do |time|
      events.each do |event|
        if time.strftime("%I:%M %p") == event.datetime.strftime("%I:%M %p")
...

Ruby two for loops cleanup?

by ttdavett.myopenid.com, July 31, 2008 00:11, 7 refactorings, tagged with rails, ruby, array, hash

times is an array of dateti...

F677fa685a2cfe8aff31f161062db3d3 Talk
1
2
3
4
    if @foo.update_attributes(params[:foo]) and @foo.bar.update_attributes(params[:bar])
      redirect_to foo_url(@parent)
    else
...

Ruby Saving multiple models in o...

by rafeco, July 29, 2008 15:56, 2 refactorings, tagged with rails, activerecord, controller

What's the best way to save...

Df2e97f18b5802e199d4920552a52d34 Talk
1
2
3
4
def tab(name, options = {})
  if name == controller.controller_name.humanize || root_of_path.humanize == name
    content_tag :li, link_to("<span>#{name}</span>", options), :class => "active"
...

Ruby How to DRY this up

by idlefingers, July 25, 2008 13:30, 8 refactorings, tagged with rails, tabs

This is for a tabbed naviga...

2b404bb55d9b5dc78841795c4b731771 Talk
1
2
3
4
module DashboardHelper
  def activity_message_for(object)
    case object.class.name
...

Ruby Dashboard

by Kryckan, July 21, 2008 21:01, 4 refactorings, tagged with rails, helper

This works but it's kind of...

C8c549e9bb39135192db53d238e19f3e Talk
1
2
3
4
def link_to_param(text, param, values)
    @qs ||= {}
    if @qs.blank?
...

Ruby Horrible method to parse a ...

by Ivan, July 17, 2008 22:45, 2 refactorings, tagged with rails, links, query string

In a Rails application, I h...

Fadf50b647fa1fb23c793ad5bd4fb6a3 Talk
1
2
3
4
def self.paged_search(query, from, category, locality, page, per_page = 10)
    query_str = []
    query_prms = []
...

Ruby Ferret, pagination and mult...

by jboss, July 17, 2008 07:34, No refactoring, tagged with rails, search, find, join, ferret, paginate

This code has multiple flaw...

3e8242329ec2756662c818a9baba76f9 Talk
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
4
xml = REXML::Document.new(data)

artists = []
...

Ruby cleaner way to limit result...

by timmyvontrimble.myopenid.com, July 14, 2008 19:12, 9 refactorings, tagged with rails, xml, array, iteration, ruby

Wow! All of these refactori...

16462f49b44507dc6522eb9bea0fce51 Talk
1
2
3
4
class Page < ActiveRecord::Base

def assigned_widgets=(string)
...

Ruby Recreating a list with acts...

by mitch, July 10, 2008 03:27, 5 refactorings, tagged with acts_as_list, rails

I tried playing with this a...

F1a42e15a7d426b8e717687794e0234b Talk
1
2
3
4
def construct_search_query
    query = '*' 
    query << 'AND (' << params[:search_all] << ')' if params[:search_all] && params[:search_all].length > 3
...

Ruby Constructing a search query

by foxdemon, July 07, 2008 05:26, 6 refactorings, tagged with search, query, rails

I want to construct a searc...

8fa97b9513b66cccc2db021782863b3b Talk
1
2
3
4
class Chat < ActiveRecord::Base
  
  KINDS = [[:office.l('Oficina'),0],['Personal',1]]
...

Ruby Multilingual Model Options

by pimp, June 09, 2008 10:21, 2 refactorings, tagged with rails, models, multilingual

So far this works a treat, ...

67c02d91e6570d0a0f6e67f96dd7ce28 Talk
1
2
3
<!-- THE XML IM TRYING TO PARSE -->
...

Ruby Trying to parse XML and pas...

by Jason, May 30, 2008 20:09, 4 refactorings, tagged with ruby, rails, parse, xml, hpricot

I am completely new to ruby...

A4e2fea57f511d697f1de55198996f23 Talk
1
2
3
4
  # OPTIMIZE: I think we can do a LOT for optimize this.
  def create
    added_counter = 0
...

Ruby Importing large collection ...

by mister, March 22, 2008 19:16, 2 refactorings, tagged with ruby, rails

This scripts get textarea w...

Avatar Talk
1
2
3
ActionController::Routing::Routes.draw do |map|
  eval(File.open(File.dirname(__FILE__) + '/../path/to/another/routes/file.rb', 'r').read)
end

Ruby Adding routes in an externa...

by jseifer, March 07, 2008 22:40, 2 refactorings, tagged with rails

I'm trying to retain the ra...

1543059f424f9fe5b7654413e6c8dc22 Talk
1
2
3
4
# in lib/product_scraper/base.rb
class ProductScraper::Base
  def product_pages
...

Ruby OO Ruby help, por favor

by misfo.myopenid.com, February 01, 2008 16:19, 3 refactorings, tagged with oo, oop, rails, lib

This is really my first att...

Cee19a4eb998343e677f7f1cfd4de5bb Talk
1
2
3
4
<table class="charge">
  <tr>
    <td colspan="100%" class="mainHeader"><%=@label.label%></td>
...

Ruby Iterating through a nested ...

by mwilliams, January 31, 2008 18:21, 2 refactorings, tagged with rails, view, table, hash, nested hash, iterator, iterate, ruby, Ruby on Rails

Good afternoon. I have a n...

4236ea6b84f4899b469e8edff4bf6d22 Talk
1
2
3
@a_to_z = Service.find(:all,:select=>'SUBSTR(name,1,1) AS letter',:group=>'SUBSTR(name,1,1)',:order=>'name').collect { |d| d.letter }

...

Ruby A to Z only linking to lett...

by aubergene, January 13, 2008 21:10, 1 refactoring, tagged with Ruby on Rails, rails, alphabet, a to z

I wanted A to Z anchor link...

B78453e586d294bcd297f8ec44ec3458 Talk
1
2
3
4
<% myid = self.current_user.id %>


...

Ruby Rails has_many count

by nootopian, January 10, 2008 21:23, 11 refactorings, tagged with rails, has_many

Hi,

I have a users users...

62c433a96de9da99d09afedcded5de76 Talk
1
2
3
4
  def planned_percent_complete
    if self.planned_complete_in_dollars != nil
      (( self.planned_complete_in_dollars.to_f / self.task.budget.to_f )  * 100).round(2)
...

Ruby Same methods, different Act...

by Chris W., January 08, 2008 18:31, 6 refactorings, tagged with ruby, rails, activerecord, dry

I know there has to be a "r...

Avatar Talk
1
2
3
4
  def self.find_matches(params)
    matches = self.find(:all)
...

Ruby Filtering Method Needs to b...

by bradly.myopenid.com, January 04, 2008 16:38, No refactoring, tagged with ruby, rails, filtering, wet

I know it looks long, but i...

0914e5093f1af95df0ab2478818856d8 Talk
1
2
3
4
before:

def list_for_blogentries(user)
...

Ruby Refactor my blog item helper

by winson, December 19, 2007 07:32, 7 refactorings, tagged with rails

I have a helper to show all...

0f9b6b2dd5ecff193f6dd78502ce1a13 Talk