Skip to content

Instantly share code, notes, and snippets.

View marinados's full-sized avatar
🤓

Marina Starkova marinados

🤓
  • Swile
  • Nantes
View GitHub Profile

Attention, François !

config/locales/en.yml

en:
  notification:
    one: You have 1 notification
    other: You have %{count} notifications

##What asset pipeline is

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass and ERB. It allows assets in your application to be automatically combined with assets from other gems.

The asset pipeline is implemented by the sprockets-rails gem, and is enabled by default. Sprockets concatenates all JavaScript files into one master .js file and all CSS files into one master .css file.
You can disable it while creating a new application by passing the --skip-sprockets option.

.nil?

Ruby method. Works on any objects, including nil and NULL

.empty?

Ruby method Used on strings, array and hashes Doesn't work on nil! Returns true if the .length is 0 --> even if there's a whitespace in a string, it won't be empty

.zipmethod

@array.zip(another_array) do |item1, item2|
    puts "#{item1} #{item2}"
  end

.cycle method for an infinite list of the same character (or turning sth into an endless array)

###Why?

Do you need to track objects by ID and look them up again, or look them up based on attributes, or even utilize some relational semantics, but have no real need for persistence?

PassiveRecord may be right for you!

###Features

  • Build relationships with belongs_to, has_one and has_many
  • Query on attributes and associations

Nested Queries

class Book < ActiveRecord::Base
  belongs_to :author
  has_many :reviews
end

class Author < ActiveRecord::Base
  has_many :books
def change_token
next_token = tokens.rotate!.first
CapsuleCRM.configure do |config|
config.api_token = next_token
end
end
def get_classes
CapsuleCRM.constants.map do |sym|
CapsuleCRM.const_get(sym)

```rails new my_api --api````

*Configure your application to start with a more limited set of middleware than normal. Specifically, it will not include any middleware primarily useful for browser applications (like cookies support) by default. *Make ApplicationController inherit from ActionController::API instead of ActionController::Base. As with middleware, this will leave out any Action Controller modules that provide functionalities primarily used by browser applications. *Configure the generators to skip generating views, helpers and assets when you generate a new resource.

```config.api_only = true````

  • In config/application.rb for existing apps

```class ApplicationController < ActionController::API````

// child combinator (>)
ol > li {
color: red;
}
// general sibling combinator (~)
.featured-image ~ p {
font-size: 90%;
}
# to_i and to_int;
# to_s and to_str;
# to_a and to_ary;
# to_h and to_hash.
"string" + other #will call to_str on other, [1,2,3] + other will call #to_ary and so on (and will raise TypeError: no implicit conversion if object not responds to this methods);
"string" * other || [1,2,3] * other # will call #to_int on other;
a, b, c = *other # will call other to_ary (and, therefore, can be used to “unpack” custom collection objects—but also can cause unintended behavior, if other implements to_ary but was not thought as a collection);
some_method(*other) #—same as above, uses other#to_ary;
some_method(**other) #—new in Ruby 2, uses other#to_hash.