Skip to content

Instantly share code, notes, and snippets.

View anoobbava's full-sized avatar
🎯
Focusing

Anoob Bava anoobbava

🎯
Focusing
View GitHub Profile
require 'spec_helper'
require 'pry'
RSpec.describe AuthorsController, type: :controller do
before(:all) do
@author = FactoryGirl.create(:author1)
@update_params = FactoryGirl.attributes_for(:author1)
end
I reviewed some common Ruby methods and grouped them by behavior.
Hopefully this helps someone else too.
[Please copy paste and fix typos, add/delete, improve from this Gist.](https://gist.github.com/dirkdirk/9209d7ea67ac57543975162713910224)
-
# Array
layout false
overriding the layout from the application.html.erb
You will notice, the layout false directive. This is because we don't want the show view inheriting from application.html layout. We will be appending this view on our home page.
@anoobbava
anoobbava / Rspec Config
Last active October 26, 2017 14:44
RSpec
1. gem install rspec
group :development, :test do
gem 'byebug', '~> 9.1'
gem 'factory_girl_rails', '~> 4.9'
gem 'launchy', '~> 2.4', '>= 2.4.3'
gem 'pry-rails', '~> 0.3.6'
gem 'rspec-rails', '~> 3.0'
@anoobbava
anoobbava / model_mistakes.rb
Created June 20, 2017 10:02
Models Mistakes
Use ? to Check Boolean Values Present:
-------------------
Department.find(5).is_sub_grouping_enabled?
Use of Bullet Gem to find the eager loading is perfect or not.
------------------------
#############
## WRONG ##
@anoobbava
anoobbava / controller_mistakes.rb
Last active June 20, 2017 13:11
mistakes controllers
Use variables as instance variables when used.
----------------------
beginners declare all the variables in controllers as instances even if it may not be required.
The problem with instance variables is that if you make a mistake, you won’t get the error message.
A good practice here is to use one or two instance variables per action
###############
## WRONG ##
###############
@anoobbava
anoobbava / ruby_mistakes.rb
Last active October 10, 2017 14:41
Ruby Mistakes
Dont misuse predicate methods:
-------
predicate methods used to return either true or false. they ends with "?"
It’s been a while since we’ve rolled out our previous article about the most common Rails mistakes that beginner developers usually make. In this regard, we aren’t going to bother you with too much of introduction and get straight to the point. This article will be dedicated to the standard approaches to Ruby development which are also called “the Ruby way”. As usual, the most critical mistakes are highlighted with RED. So, let’s find out what exactly newbies do wrong/forget to do or don’t do at all.
They misuse predicates
A predicate is a method that answers a specific question and always returns either “yes” or “no”. It’s not supposed to affect any other piece of code or perform any additional actions. According to the Ruby on Rails style guides, predicates are followed by a question mark at the end of the method name.
############
## WRONG ##
@anoobbava
anoobbava / Collect_Select_Map_Inject_Reject_Detect.rb
Created August 4, 2017 05:54 — forked from vaichidrewar/Collect_Select_Map_Inject_Reject_Detect.rb
how to use collect or map or select or each or inject or reject Or when to use each vs collect vs map vs select vs each vs inject vs reject
map and collect are same http://stackoverflow.com/questions/5254732/difference-between-map-and-collect-in-ruby
http://matthewcarriere.com/2008/06/23/using-select-reject-collect-inject-and-detect/
1. Use select or reject if you need to select or reject items based on a condition.
2. Use collect if you need to build an array of the results from logic in the block.
3. Use inject if you need to accumulate, total, or concatenate array values together.
4. Use detect if you need to find an item in an array.
@anoobbava
anoobbava / association_models.rb
Created October 4, 2017 05:42
Association Examples in Rails
1.belongs_to association:
---------------------
- Student and College:
- a student belongs_to college
- college_id is present in the college
- Example:
**************
class Student < ApplicationRecord
belongs_to :college
@anoobbava
anoobbava / .travis.yml
Last active November 15, 2017 16:27
travis YML Sample
language: ruby
rvm:
- 2.3.1
env:
- DB=sqlite
before_script:
- mysql -e 'create database test;'
script:
- RAILS_ENV=test bundle exec rake db:migrate --trace
- bundle exec rspec && CODECLIMATE_REPO_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX bundle exec codeclimate-test-reporter