You’ll probably have to be more verbose here
name = "Blue Jeans"
model = Product.where('lower(name) = ?', name.downcase).first
model ||= Product.create(:name => name)
More Related Contents:
- Rails ActiveRecord methods in different places [closed]
- Eager load polymorphic
- accepts_nested_attributes_for with find_or_create?
- ActiveRecord.find(array_of_ids), preserving order
- Rails order by results count of has_many association
- Using Rails serialize to save hash to database
- Setting session timeout in Rails 3
- How to handle Ruby on Rails error: “Please install the postgresql adapter: `gem install activerecord-postgresql-adapter'”
- How to query a model based on attribute of another model which belongs to the first model?
- Multiple databases in Rails
- Rails: ActiveRecord query based on association value
- Rails 3, has_one / has_many with lambda condition
- Rails ActiveRecord: Find All Users Except Current User
- query , can not select column count
- How to use ActiveRecord in a ruby script outside Rails?
- Creating a PostgreSQL sequence to a field (which is not the ID of the record)
- Validate uniqueness of multiple columns
- Rails: How do I create a default value for attributes in Rails activerecord’s model? [duplicate]
- Using helpers in model: how do I include helper dependencies?
- What are the brackets [5.1] after ActiveRecord Migration and how does it work? [duplicate]
- Rails – Validate Presence Of Association?
- Do rails rake tasks provide access to ActiveRecord models?
- delete_all vs destroy_all?
- Rails 3 migrations: Adding reference column?
- Converting an array of objects to ActiveRecord::Relation
- how to add records to has_many :through association in rails
- How to implement bulk insert in Rails 3
- PGError: ERROR: aggregates not allowed in WHERE clause on a AR query of an object and its has_many objects
- How do I avoid a race condition in my Rails app?
- Rails: Order with nulls last