1
2
3
4
h = {:asdf => 'toto', :titi => 42}
 => {:asdf=>"toto", :titi=>42}
h2 = HashWithIndifferentAccess.new(h)
...

Ruby On val.respond_to? x, but val....

by Fabien Jakimowicz, July 07, 2010 11:03

If your are in Rails projec...

Be1e3ee645d23c95ba650c21bc885927 Talk
1
2
3
class Round < ActiveRecord::Base
  belongs_to :season
...

Ruby On Validate the nested model

by Fabien Jakimowicz, March 24, 2009 12:42

I'm not sure why you need t...

Be1e3ee645d23c95ba650c21bc885927 Talk
1
2
3
class User < ActiveRecord::Base
  has_many :classrooms
...

Ruby On Too many for loops

by Fabien Jakimowicz, February 25, 2009 14:20

You can optimize a little b...

Be1e3ee645d23c95ba650c21bc885927 Talk
1
2
3
class Announcement < ActiveRecord::Base
  ANNONCEMENT_TYPES = {'squad'    => :deliver_squad_announcement,
...

Ruby On Re-Refactor Mailer Conditions

by Fabien Jakimowicz, February 14, 2009 10:46

You should use callbacks an...

Be1e3ee645d23c95ba650c21bc885927 Talk
1
2
3
add_index(:accounts, [:branch_id, :party_id], :unique => true)

...

Ruby On While loop to get unique value

by Fabien Jakimowicz, February 12, 2009 13:34

If you are using ActiveReco...

Be1e3ee645d23c95ba650c21bc885927 Talk
1
zcat database_dump.sql.gz | mysql -u username -h host -p password database

Bash On Unzip large database dump d...

by Fabien Jakimowicz, February 12, 2009 12:36

Not really better, but you ...

Be1e3ee645d23c95ba650c21bc885927 Talk
1
2
3
def caesar(text, shift)
  text.split('').collect {|letter| (letter[0] + shift).chr}.join
end

Ruby On Caesar Cipher

by Fabien Jakimowicz, August 09, 2008 11:34
Be1e3ee645d23c95ba650c21bc885927 Talk
1
2
3
class Account < ActiveRecord::Base
  has_many :websites
...

Ruby On Rails - Multiple instances ...

by Fabien Jakimowicz, August 03, 2008 12:48 Star_fullStar_fullStar_fullStar_fullStar_full

You should move a lot of lo...

Be1e3ee645d23c95ba650c21bc885927 Talk
1
2
3
class MyaccountController < ApplicationController
  before_filter :load_users, :only => [ 'account_details', 'show_email_box', 'show_mobile_box' ]
...

Ruby On How to make instance variab...

by Fabien Jakimowicz, July 31, 2008 13:33 Star_fullStar_fullStar_fullStar_full

You can use a before filter...

Be1e3ee645d23c95ba650c21bc885927 Talk
1
2
3
4
def update_foo_and_bar
  # You can also use @foo.class.transaction and @foo.bar.class.transaction if you have multiple database at the same time
  ActiveRecord::Base.transaction {@foo.update_attributes!(params[:foo]) and @foo.bar.update_attributes!(params[:bar])}
...

Ruby On Saving multiple models in o...

by Fabien Jakimowicz, July 29, 2008 22:21

there is a lot of way to cl...

Be1e3ee645d23c95ba650c21bc885927 Talk
1
2
3
4
xml = REXML::Document.new(data)

artists = xml.elements.to_a('//artist')[0..limit].collect do |artist|
...

Ruby On cleaner way to limit result...

by Fabien Jakimowicz, July 14, 2008 23:38

i'm not familiar with REXML...

Be1e3ee645d23c95ba650c21bc885927 Talk
1
['foo', 'bar', 'baz'].each_with_index {|j, i| puts "#{i} #{j}"}

Ruby On Python's enumerate in Ruby?

by Fabien Jakimowicz, July 14, 2008 23:23 Star_fullStar_fullStar_fullStar_fullStar_full
Be1e3ee645d23c95ba650c21bc885927 Talk

Ruby On collecting attributes from ...

by Fabien Jakimowicz, June 17, 2008 15:32 Star_fullStar_fullStar_full

I thought the same about ht...

Be1e3ee645d23c95ba650c21bc885927 Talk
1
2
3
4
# Rails < 2.0
Carrier.find(:all).collect {|d| [d.id, d.name]}.flatten

...

Ruby On collecting attributes from ...

by Fabien Jakimowicz, June 17, 2008 11:52 Star_fullStar_fullStar_fullStar_fullStar_full
Be1e3ee645d23c95ba650c21bc885927 Talk