Skip to content

Instantly share code, notes, and snippets.

View Maxoos's full-sized avatar

Maxoos

  • Melbourne, Australia
View GitHub Profile
@mlangenberg
mlangenberg / ams_cache.rb
Last active August 29, 2015 13:58
One approach to cache ActiveModelSerializer representations with ActiveRecord objects
class User < ActiveRecord::Base; end;
class Post < ActiveRecord::Base; end;
class Comment < ActiveRecord::Base; end;
class AuthorSerializer < ActiveModel::Serializer
attributes :id, :name :created_at, :updated_at
end
class PostSerializer < ActiveModel::Serializer
attributes :id, :body :created_at, :updated_at
@Agowan
Agowan / album_form.rb
Last active April 5, 2016 20:50
A simple way to use has_many between form objects using Virtus.The problem I had was to get validations working with fields_for in the view, but still have the flexibility and full control using virtus instead of active record models.And I added a way of checking for sanitised args in rails 4.
# encoding: utf-8
class AlbumForm < BaseForm
has_many :songs, class_name: 'SongForm'
validates :songs, form_collection: true
end
@samnang
samnang / 1_decorator.rb
Created September 15, 2013 03:21
Decorator vs Form Object vs Service Object?
class FacebookCommentNotifer
def initialize(comment)
@comment = comment
end
def save
@comment.save && post_to_wall
end
private
@Jared-Prime
Jared-Prime / gist:2423065
Created April 19, 2012 18:57
Converting RGB to HEX in Ruby
# Beginning Rubyists: simply run >> ruby hex-convertions.rb to see examples
# or use irb to build the code on the fly
# you can convert HEX to DEC using the method .to_i(base),
# which converts a string to a decimal number from the specified base number
puts "00".to_i(16)
puts "FF".to_i(16)