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
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
We sometimes need unique and random tokens in our web apps. Here is how wetypically build it. class User < ActiveRecord::Base before_create :set_access_token private def set_access_token self.access_token = generate_token end def generate_token loop do token = SecureRandom.hex(10) break token unless User.where(access_token: token).exists? end endendhas_secure_token in Rails 5Rails 5has added has_s
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く