Skip to content

Instantly share code, notes, and snippets.

View sylow's full-sized avatar

Gökhan Arlı sylow

View GitHub Profile
@sylow
sylow / fields_for.rb
Last active February 27, 2017 03:07
has_many :through in Rails with TB2
# --- model
class Announcement < ActiveRecord::Base
belongs_to :user
has_many :announcement_rooms, dependent: :delete_all
has_many :rooms, through: :announcement_rooms
end
# --- controller
@sylow
sylow / contract&op&test.rb
Last active December 22, 2015 12:34
Works in the browser but could not make it work in the operation test, anyone spots the issue?
# contract
property :logo, skip_if: :all_blank,
prepopulator: ->(options) { self.logo = Image.new },
populator: ->(fragment, model, options) { model || self.logo = Image.new } do
property :_destroy, virtual: true
property :data
end
# models
#challenge.rb