#more elegante way? sector = Sector.create(:name => name) unless sector = Sector.find_by_name(sector)
Ruby more elegant way
# 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 ...
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...
<%= 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
any help appreciated!
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...
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 ...
class Event < ActiveRecord::Base before_create :set_time_for_length after_initialize :set_time_for_length ...
Ruby Event: set end time based o...
What I can do is this:
e =...
# 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...
class Activity < ActiveRecord::Base has_and_belongs_to_many :products has_and_belongs_to_many :articles ...
Ruby find_by in two has_and_belo...
Using: Article.first.products
# 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...
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
How can I turn this into so...
class Item < ActiveRecord::Base ALL_VOTES = "all_votes" SCORE = "score" ...
Ruby Complex query in Ruby on Ra...
I have a method called rank...
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...
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...
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...
What's the best way to save...
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, ...
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...
I know there has to be a "r...
def which_class?
if self.language == "C/C++"
self.language = "sh_cpp"
...
Ruby class picker
language is a column in a c...
no ideas about it, rails 3....