Skip to content

Instantly share code, notes, and snippets.

@madwork
madwork / attachment.rb
Last active July 25, 2021 09:13
Polymorphic attachments with CarrierWave and nested_attributes
class Attachment < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader
# Associations
belongs_to :attached_item, polymorphic: true
# Validations
validates_presence_of :attachment
@olistik
olistik / gist:2627011
Last active August 12, 2021 06:39
Ubuntu 12.10 setup (rbenv/RVM, Janus, PostgreSQL)

Ubuntu 12.10 setup (rbenv/RVM, Janus, PostgreSQL)

Basic pre-requisites

  • Some utilities:
sudo apt-get install vim tmux git curl
  • Copy/paste from the command line:
@schoren
schoren / _custom_multiselect.html.haml
Created July 19, 2011 19:30
Custom view for rails_admin to create related HABTM records
:ruby
config = field.associated_model_config
selected = field.bindings[:object].send(field.association[:name])
selected_ids = selected.map(&:id)
xhr = field.associated_collection_count > 100
if xhr
collection = selected.map do |o|
[o.send(config.object_label_method), o.id]
end
else