#more elegante way? 
sector = Sector.create(:name => name) unless sector = Sector.find_by_name(sector)

Ruby more elegant way

by RoadHouse, December 01, 2011 09:52, 5 refactorings, tagged with ruby, activerecord, rails3

no ideas about it, rails 3....

70089e712ed13abb99bec89bd5bfba77 Talk
# chip away at the bonuses play through amounts
    bet_through_credit_remaining = self.wager
    self.user.bonuses.ranked.each do |bonus|
...

Ruby apply a credit over an orde...

by philrosenstein.myopenid.com, October 21, 2011 15:14, 15 refactorings, tagged with rails, activerecord, array, 2.3.x

example: if the credit is ...

20bffe332e5534f3ea328698ecb0a938 Talk
composed_of :assistant_fee,
    :class_name => "Money",
    :mapping => [%w(assistant_fee_in_cents cents), %w(currency currency_as_string)],
...

Ruby Refactoring multiple compos...

by https://www.google.com/accounts/o8/id?id=AItOawlg3KkPp_EslfoIAWbF6uZYScrro2jwb-E, April 03, 2011 01:11, 1 refactoring, tagged with rails, ruby, activerecord

I have a model that has sev...

55502f40dc8b7c769880b10874abc9d0 Talk
<%= select_tag :editor_id, options_for_select(Member.where(:role => :editor).select {|m| m.authentications.count > 0 }.collect { |u| [u.name, u.id]  } ) %

Ruby messy Rails select

by bruno antunes, March 24, 2011 14:54, 2 refactorings, tagged with rails, ruby, activerecord

any help appreciated!

1b491994d6011d720e332af6e1ffd03b Talk
STATES = ['address', 'shipping', 'receipt', 'confirmation']

def next_state!
...

Ruby Next Array Value

by https://www.google.com/accounts/o8/id?id=AItOawlhtGOurcXKMALBiVsK30cQwELBGpZuPXs, December 28, 2010 22:22, 4 refactorings, tagged with rails, ruby, activerecord

Trying to figure out a bett...

55502f40dc8b7c769880b10874abc9d0 Talk
def self.find_for(options = {})
    scope = scoped
    scope = scope.where(:hook => options[:hook].to_s)  if options[:hook]
...

Ruby ActiveRecord query construc...

by https://www.google.com/accounts/o8/id?id=AItOawmLF7gR3CIpZoZXbwO7fiD2QWYltD3lwpM, December 23, 2010 15:27, 1 refactoring, tagged with rails, sql, activerecord, rails3, arel

Rails 3.0.3

This method ...

55502f40dc8b7c769880b10874abc9d0 Talk
class Event < ActiveRecord::Base
  before_create :set_time_for_length
  after_initialize :set_time_for_length
...

Ruby Event: set end time based o...

by Luke, November 26, 2010 02:20, 1 refactoring, tagged with activerecord

What I can do is this:
e =...

1566d4066e11205ec3e3aaeeaf89348b Talk
# link_categories has_many links
create_table "link_categories", :force => true do |t|
  t.string   "name"
...

Ruby Find records according to r...

by https://www.google.com/accounts/o8/id?id=AItOawl_CInyr4p6Fw9fCXT3DYEGIiMyGOQDomw, August 02, 2010 18:43, 1 refactoring, tagged with rails, sql, ruby, activerecord

I have a method (LinkCatego...

55502f40dc8b7c769880b10874abc9d0 Talk
class Activity < ActiveRecord::Base
  has_and_belongs_to_many :products
  has_and_belongs_to_many :articles
...

Ruby find_by in two has_and_belo...

by rduarte, March 24, 2010 21:03, 2 refactorings, tagged with rails, ruby, activerecord

Using: Article.first.products

4203bf83f438804dde849b48de826158 Talk
# Associations
#
# User: has_many :sources, :as => :sourceable, :dependent => :destroy
...

Ruby Get child elements from a o...

by Chris, March 11, 2010 08:27, 2 refactorings, tagged with activerecord, model, rails activerecord, assoziations

For a object (e.g. user), I...

5d7c8b8f2de06c07b2bf0848d20ce71f Talk
Clip.find_by_sql(["select * from clips where not exists
        (select 'clip_id' from histories where histories.clip_id = clips.id
        and histories.user_id = ?) ORDER BY clips.created_at DESC LIMIT 20", user.id])

Ruby ActiveRecord find_by_sql

by David, January 17, 2010 20:52, 5 refactorings, tagged with rails, sql, short, ruby, activerecord

How can I turn this into so...

D41d8cd98f00b204e9800998ecf8427e Talk
class Item < ActiveRecord::Base
  ALL_VOTES = "all_votes"
  SCORE = "score"
...

Ruby Complex query in Ruby on Ra...

by Pablo, January 10, 2010 13:27, No refactoring, tagged with rails, sql, ruby, activerecord, joins

I have a method called rank...

931970b8dc51b72e05e3a12b88612d61 Talk
class User < ActiveRecord::Base
  has_many :assets, :foreign_key => 'creator_id'

...

Ruby Change a finder method w/ p...

by saizai.livejournal.com, June 06, 2009 00:16, No refactoring, tagged with rails, activerecord, associations, named_scope

How do I turn this into a h...

237338834f2f8948e862e91392a8c1b4 Talk
if @chosen_campaign.network.nil?
  case params[:type]
  when "moderated"
...

Ruby 2 Crossed conditions for Ac...

by gkochan.myopenid.com, April 16, 2009 14:24, -1 refactorings, tagged with activerecord, find, crossed conditions

I can't figure out any nice...

A0317a752d14a9ba201370824cea5815 Talk
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
require 'rubygems'
require 'active_record'
require 'benchmark'
...

Ruby ActiveRecord threaded bench...

by Kevin Williams, February 20, 2008 04:33, 6 refactorings, tagged with orm, activerecord, benchmark

first of three benchmarks, ...

267942571862781dd912de6482a35f46 Talk
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 rails, ruby, activerecord, dry

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

D41d8cd98f00b204e9800998ecf8427e Talk
def which_class?
  if self.language == "C/C++"
     self.language = "sh_cpp"
...

Ruby class picker

by Garrett, December 10, 2007 00:04, 8 refactorings, tagged with rails, ruby, activerecord, model

language is a column in a c...

E9674d02c33d1d711a462026f40bbaf4 Talk