Skip to content

Instantly share code, notes, and snippets.

@mort
Created August 3, 2011 16:25
Show Gist options
  • Select an option

  • Save mort/1123063 to your computer and use it in GitHub Desktop.

Select an option

Save mort/1123063 to your computer and use it in GitHub Desktop.
ree-1.8.7-2011.03 :147 > k = User.first.kbadges.find_or_create_by_title(:title => 'Foo', :variant=>"collectible", :badge_type=>"newbish", :description=>"Fashion gems are fashion!", :grant_activity_date=>"2009-10-28 08:02:29 UTC")
=> #<Kbadge id: nil, user_id: 1, title: {:variant=>"collectible", :badge_type=>"newbish", :description=>"Fashion gems are fashion!", :title=>"Foo", :grant_activity_date=>"2009-10-28 08:02:29 UTC"}, description: nil, variant: nil, badge_type: nil, badge_count: 0, grant_activity_date: nil, created_at: nil, updated_at: nil>
ree-1.8.7-2011.03 :148 > k.title
=> {:variant=>"collectible", :badge_type=>"newbish", :description=>"Fashion gems are fashion!", :title=>"Foo", :grant_activity_date=>"2009-10-28 08:02:29 UTC"}
@dagi3d
Copy link

dagi3d commented Aug 3, 2011

class Foo < ActiveRecord::Base
attr_protected :bar
validates_presence_of :bar
end

ruby-1.8.7-p334 :003 > foo = Foo.find_or_create_by_bar(:bar => "BAR", :foobar => "FOOBAR")
=> #Foo id: nil, bar: nil, foobar: "FOOBAR", created_at: nil, updated_at: nil>

@mort
Copy link
Author

mort commented Aug 4, 2011

Sí, solucionado con usar la sintaxis de bloque para los atributos. Gracias mil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment