stalno u pokretu

< IT & tech


12. 09. 2014. back end * ruby

ActiveRecord notes

Contents


Uniqueness on a combination of fields

In the model:

validates :name, presence: true, uniqueness: { scope: :genus, message: Species::NAME_GENUS_VALIDATION_ERROR }
validates :genus, presence: true

In the spec:

subject { FactoryGirl.create(:species) }
it { is_expected.to validate_uniqueness_of(:name).scoped_to(:genus).with_message(Species::NAME_GENUS_VALIDATION_ERROR) }

Before testing uniqueness a record must be created.
In the migration:

add_index :species, [:name, :genus]

The index should be added on to the fields to enforce field combination uniqueness in the database.

Resources


Inclusion in array

In the model: validates :role, presence: true, inclusion: {in: ROLES}

In the spec:

it { is_expected.to ensure_inclusion_of(:role).in_array(User::ROLES) }

Getting all model associations

model_class(model).reflect_on_all_associations.map { |a| a.name }

Overriding model getters and setters

def habitats
  read_attribute(:habitats)
end

def habitats=(value)
  write_attribute(:habitats, value)
end

Serialization

In model:

serialize :substrates, JSON

In controller:

def permitted_params
  @params ||= params.require(:characteristics).permit(PUBLIC_FIELDS).tap do |white_listed|
    white_listed[:substrates] = params[:characteristics][:substrates]
  end
end

When searching:

Characteristic.where(substrates: ["flash", "branches", "leaves"].to_json)

resources


Related posts


15. 08. 2014. api * back end * ruby
API - design, implementation, testing

notes and resources
[ reading time: ~ 3 min. ]

01. 09. 2014. api * back end * bdd / tdd * cucumber * ruby * ruby gem
Developing rails REST API with Cucumber

json_spec, writing the definitions, checking the http headers, testing authentication...
[ reading time: ~ 3 min. ]

03. 09. 2014. api * back end * ruby * ruby gem * security
Devise as authentication solution for rails API

Authentication token, the use of sessions, intsallation and setup, configuring the model, the routes, application controller, custom devise controllers, testing the controllers
[ reading time: ~ 9 min. ]

07. 09. 2014. api * back end * ruby
Building a JSON API in rails

notes
[ reading time: ~ 1 min. ]

17. 09. 2014. back end * i18n&l10n * ruby
i18n gem advanced features – Ruby on Rails internationalization

Using Different Backends for Ruby i18n gem, chaining backends, caching is an i18n gem advanced feature, fallbacks, Translation Metadata, cascading lookups, translation symlinks, using custom exception handlers
[ reading time: ~ 14 min. ]

17. 09. 2014. back end * i18n&l10n * padrino * ruby * sinatra
Internationalization for Ruby – i18n gem

i18n for plain Ruby & the i18n gem, i18n for Ruby on Rails, i18n for Sinatra, i18n for Padrino
[ reading time: ~ 20 min. ]

17. 09. 2014. back end * i18n&l10n * ruby
Internationalization for Ruby with the r18n gem

Installation and setup, translation lookup, filters for translations processing, pluralization, translating activeRecord models and plain Ruby objects, locale settings, r18n wrappers for rails and sinatra, r18n vs i18n
[ reading time: ~ 9 min. ]

17. 09. 2014. back end * gettext * i18n&l10n * ruby
Ruby gettext internationalization tutorial on using the fast_gettext gem

Setup, translation lookup, managing translations (MO/PO, db, yaml), rails plugin, pluralization, defaults, multiple repositories, logging...
[ reading time: ~ 9 min. ]

22. 11. 2014. back end * deployment * ruby
rails deployment

Setting up Debian 7 server on VPS, nginx, php-fpm, ruby, unicorn/phusion passanger, essentials, ssh keys, capistrano...
[ reading time: ~ 2 min. ]

10. 08. 2014. api * back end
Representational state transfer (REST)

notes
[ reading time: ~ 3 min. ]

21. 08. 2014. database * ruby
Adding UUID to rails

notes
[ reading time: ~ 1 min. ]

04. 09. 2014. api * back end
Design principles of the REST-ful JSON API (HATEOAS)

REST, JSON, API, HATEOAS, media types, top level resource representations, url templates, compound documents, urls, responses, errors, JSend response types, HTTP Status codes
[ reading time: ~ 12 min. ]

17. 09. 2014. back end * cakephp * codeigniter * i18n&l10n * php * symfony * yii * zend
Internationalization How To for the 5 most popular PHP frameworks

In this how-To you will read about using CodeIgniter, CakePHP, Zend, Yii and Symfony
[ reading time: ~ 8 min. ]

17. 09. 2014. back end * fuelphp * i18n&l10n * laravel * php
PHP internationalization frameworks: Laravel and FuelPHP

The article covers two more PHP frameworks that are frequently used, Laravel and FuelPHP
[ reading time: ~ 6 min. ]

17. 09. 2014. back end * i18n&l10n * php
PHP internationalization – i18n mechanisms tutorial

Static web and internationalization, dynamic web applications, localizing strings directly in the code, storing the strings in a relational database, message catalogues (string arrays), JSON, use of resource files
[ reading time: ~ 10 min. ]

17. 09. 2014. back end * gettext * i18n&l10n * php
PHP internationalization with gettext tutorial

Installation, portable object template files, plurals, an example of a PO file, directory structure, machine object files, gettext caching problems, setting up PHP for internationalization with gettext...
[ reading time: ~ 18 min. ]

17. 09. 2014. back end * i18n&l10n
Resource file formats

ini files, properties files, iOS .strings files, YAML files, RESX and RESW files, RESJSON files
[ reading time: ~ 4 min. ]

24. 11. 2014. back end * dev_tool
nginx notes

notes
[ reading time: ~ 1 min. ]

10. 12. 2014. back end * ruby gem
Capistrano

notes
[ reading time: ~ 1 min. ]

Ovaj sajt ne sadrži first party kukije i druge mehanizme za aktivno praćenje poseta/ponašanja (facebook, google analytics, itd...). Na nekim stranicama se nalaze embedovani youtube video klipovi i google mape koji učitavaju svoje kukije.