Skip to content

Instantly share code, notes, and snippets.

View vinniefranco's full-sized avatar
🏡
WFH

Vincent Franco vinniefranco

🏡
WFH
View GitHub Profile
SPA.extend("SearchableList", (function($) {
var my = {},
options = {
url: "/",
clearCallback: function() {},
clickCallback: function() {},
list: {},
guid: null,
itemTemplate: "",
name: "List"
# Create a new image
ruby-1.9.2-p136 :120 > image = Image.new()
=> #<Image id: nil, table_name: nil, table_id: nil, title: nil, description: nil, tiny: nil, small: nil, medium: nil, large: nil, original: nil, dcreate: nil, asset_file_name: nil, asset_content_type: nil, asset_file_size: nil, asset_updated_at: nil, asset_remote_url: nil>
# Set a style dynamically
ruby-1.9.2-p136 :126 > image.asset.styles[:large] = Paperclip::Style.new(:large, '300x300#', image.asset)
=> #<Paperclip::Style:0x00000100f0f5e0 @name=:large, @attachment=/assets/original/missing.png, @geometry="300x300#", @format=nil, @other_args={}>
# Add a new asset and BOOM
ruby-1.9.2-p136 :127 > image.asset = File.new(Rails.root+'public/images/rails.png')
class Image < ActiveRecord::Base
attr_accessor :asset_url
# This should pull in dynamic styles based of what
# model is calling it Articles, Events, etc.
has_attached_file :asset,
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => "/media/:class/:attachment/:style.:filename",
= form_for @gallery, :html => { :multipart => true }, :remote => true do |f|
%ol.dialog.form
%li.text
= f.label :title
= f.text_field :title
%li.select
= f.label :parent_id, 'Parent'
= f.select :parent_id , @galleries.collect {|g| [g.title, g.id]}, { :include_blank => 'Pick a parent' }
%li.file
- f.fields_for :image do |image|
json.gallery do |g|
g.info do |info|
info.title @gallery.title if @gallery.title
info.image @gallery.image.l(:medium) if @gallery.image
info.parent_id @gallery.parent_id if @gallery.parent_id
info.root true unless @gallery.parent_id
end
@gallery.photos.each do |photo|
g.photos do |p|
p.id photo.id
class PhotoGallery < ActiveRecord::Base
# Legacy work
self.inheritance_column = 'inheritance_type'
set_table_name :galleries
alias_attribute :created_at, :dcreate
belongs_to :client,
:conditions => { :table_name => :galleries,
:type => :photos }
var Gallery = (function() {
var opts = {},
cont = {};
function displayMeta (data) {
if ( ! data.info) { opts.html(''); return; }
var meta = data.info,
str = "<img src='"+meta.image+"'><h3>"+meta.title+"</h3>";
var Layout = (function() {
/*
TODO Maybe some default modules?
*/
var modules = modules || {};
function addModule(name, callback) {
modules[name] = callback;
}
function applyJSON(json) {
json.gallery do |g|
g.info do |info|
info.title @gallery.title if @gallery.title
info.image @gallery.image.l(:medium) if @gallery.image
info.parent_id @gallery.parent_id if @gallery.parent_id
info.root true unless @gallery.parent_id
end
@gallery.photos.each do |photo|
g.photos do |p|
p.id photo.id
@vinniefranco
vinniefranco / gist:786620
Created January 19, 2011 18:44
Fixes :limit => 0 for enumerated columns in rails 3
# Fixes :limit => 0 on enumerated columns, now you can test!
module ActiveRecord
module ConnectionAdapters
class Column
def extract_limit_with_enum(sql_type)
sql_type.scan(/enum/i)? 255 : extract_limit_without_enum(sql_type)
end
alias_method_chain :extract_limit, :enum
end
end