Skip to content

Instantly share code, notes, and snippets.

@isfando
isfando / index.md
Created June 10, 2021 07:00 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@isfando
isfando / arel_cheatsheet_on_steroids.md
Created April 28, 2021 07:36 — forked from ProGM/arel_cheatsheet_on_steroids.md
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias

@isfando
isfando / Generating_Migrations.md
Created April 21, 2021 15:01 — forked from alexpchin/Generating_Migrations.md
Generating Migrations

Generating Migrations

Migrations are a feature of Active Record that allows you to evolve your database schema over time. Rather than write schema modifications in pure SQL, migrations allow you to use an easy Ruby DSL to describe changes to your tables.

Another way of thinking about them is like a kind of version control (like git) for your application's database - only not as cool as Git (because Git rules).

##Each database starts empty Every database starts empty. Adding information to a database can be described as a series of steps, one after another... Migrations allow developers to save the most important steps like creating tables or adding columns. Later you can rollback to before these changes if something goes wrong, although you might lose data if you do this!

@isfando
isfando / ActiveRecord Cheat Sheet v1
Created April 9, 2021 07:02 — forked from jessieay/ActiveRecord Cheat Sheet v1
Active Record cheat sheet with examples of queries I've needed most so far
ActiveRecord cheat sheet / EXAMPLES
INSTALL
=======
$ gem install activerecord
in GEMFILE: gem ‘activerecord’
REQUIRE
=======
require ‘active_record’
@isfando
isfando / nil_empty_blank_present_ffdierence_in_ruby
Created January 4, 2021 09:47 — forked from pythonicrubyist/nil_empty_blank_present_ffdierence_in_ruby
Difference between nil?, empty?, blank? and present? in Ruby and Ruby on Rasils.
# nil? can be used on any Ruby object. It returns true only if the object is nil.
nil.nil? # => true
[].nil? # => false
{}.nil? # => false
"".nil? # => false
" ".nil? # => false
true.nil? # => false
# empty? can be used on some Ruby objects including Arrays, Hashes and Strings. It returns true only if the object's length is zero.
nil.empty? # NoMethodError: undefined method `empty?' for nil:NilClass
@isfando
isfando / rails_activerecord_cheatsheet.md
Created August 25, 2020 09:07 — forked from amejiarosario/rails_activerecord_cheatsheet.md
Rails ActiveRecord (association) - Cheatsheet

Rails ActiveRecord (association) - Cheatsheet

http://guides.rubyonrails.org/association_basics.html

Types of associations

  • belongs_to : TABLE_NAME
  • has_one : TABLE_NAME [:through => :TABLE_NAME]
  • has_many : TABLE_NAME [:through => :TABLE_NAME]
  • has_and_belongs_to_many : TABLE_NAME [:join_table => :TABLE_NAME]
@isfando
isfando / capybara cheat sheet
Created August 19, 2020 09:30 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger