|
Post.where(author: 'admin')
|
|
Post.where(author: 'admin').last
|
|
Post.find_by(title: 'Rails 4', author: 'admin')
|
|
Post.find_or_initialize_by(title: 'Rails 4')
|
|
Post.find_or_create_by(title: 'Rails 4')
|
|
@post.update(post_params) - preferred
|
|
@post.update_columns(post_params) - executes directly in database(skip validation)
|
|
scope :sold, ->{ where(state: 'sold') }
|
|
default_scope ->{ where(state: 'available') }
|
|
scope :recent, ->{ where(published_at: 2.weeks.ago) }
|
|
scope :recent_red, ->{ recent.where(color: 'red') }
|
|
Post.where.not(author: author)
|
|
User.order(:name, created_at: :desc)
|
|
Post.includes(:comments).where(comments: { name: 'foo' })
|
|
Post.includes(:comments).where('comments.name' => 'foo')
|
|
Post.includes(:comments).order('comments.name')
|
|
match '/items/:id/purchase', to: 'items#purchase', via: :post
|
|
match '/items/:id/purchase', to: 'items#purchase', via: :all
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.