BigBinary BlogWe craft blog posts about what we have learned so far and we have published 608 blog posts about Ruby on Rails, ReactJS, React Native, open source, engineering & design.

Rails already provides methods for creating class level and module levelvariables in the form ofcattr** and mattr** suite of methods. In Rails 5, we can go a step further and createthread specific class or module level variables. Here is an example which demonstrates an example on how to use it. module CurrentScope thread_mattr_accessor :user_permissionsendclass ApplicationController < ActionContr
Rails 5has added OR methodto Active Relation for generating queries with OR clause. >> Post.where(id: 1).or(Post.where(title: 'Learn Rails')) SELECT "posts".* FROM "posts" WHERE ("posts"."id" = ? OR "posts"."title" = ?) [["id", 1], ["title", "Learn Rails"]]=> <ActiveRecord::Relation [#<Post id: 1, title: 'Rails'>]>This returns ActiveRecord::Relation object, which is logical union of tworelations.
In Rails 4.x, it is not possible to have destroy dependency on both sides of a bi-directional association between the two models as it would result in an infinite callback loop causing SystemStackError: stack level too deep. 1 2class User < ActiveRecord::Base 3 has_one :profile, dependent: :destroy 4end 5 6class Profile < ActiveRecord::Base 7 belongs_to :user, dependent: :destroy 8end 9 Copy 1 2>>
In Rails 4.x, when we save an ActiveRecord object then Rails automaticallyupdates fields updated_at or updated_on. >> user = User.new(name: 'John', email: 'john@example.com')>> user.save INSERT INTO "users" ("name", "created_at", "updated_at", "email") VALUES (?, ?, ?, ?) [["name", "John"], ["created_at", 2016-03-16 09:12:44 UTC], ["updated_at", 2016-03-16 09:12:44 UTC], ["email", "john@example.co
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く