Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrislerum/133852 to your computer and use it in GitHub Desktop.
Save chrislerum/133852 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => {:thumb => '100x100>'}
end
###########
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :avatar_file_name
t.string :avatar_content_type
t.integer :avatar_file_size
t.datetime :avatar_updated_at
# other columns
end
end
def self.down
drop_table :users
end
end
###########
class UsersController < ApplicationController
active_scaffold :users do |config|
config.create.multipart = true
config.update.multipart = true
config.columns.exclude :avatar_file_size, :avatar_updated_at, :avatar_file_name, :avatar_content_type
config.columns << :avatar
end
end
###########
module UsersHelper
def avatar_form_column(record, input_name)
file_field :record, :avatar
end
def avatar_column(user)
image_tag user.avatar.url(:thumb)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment