Skip to content

Instantly share code, notes, and snippets.

View marinados's full-sized avatar
:shipit:

Marina Starkova marinados

:shipit:
  • Swile
  • Nantes
View GitHub Profile

```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````

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)

Nested Queries

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

class Author < ActiveRecord::Base
  has_many :books

###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

.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)

.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

##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.

Attention, François !

config/locales/en.yml

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