klondike (owner)

Forks

Revisions

gist: 37761 Download_button fork
public
Public Clone URL: git://gist.github.com/37761.git
Embed All Files: show embed
activescaffold-paperclip.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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