mirror of
https://github.com/fspc/BikeShed-1.git
synced 2025-02-28 08:43:23 -05:00
User avatar upload at sign up
This commit is contained in:
parent
8a8c82f5b7
commit
a68e7eca56
1
Gemfile
1
Gemfile
@ -18,6 +18,7 @@ gem 'jquery-rails', '~> 2.0'
|
||||
gem 'pg', '~> 0.17.1'
|
||||
gem 'will_paginate', '~> 3.0.3'
|
||||
gem 'jbuilder', '~> 2.0.3'
|
||||
gem 'paperclip', '~> 4.3'
|
||||
|
||||
# Assets
|
||||
gem 'sass-rails', '~> 3.0'
|
||||
|
11
Gemfile.lock
11
Gemfile.lock
@ -57,7 +57,10 @@ GEM
|
||||
xpath (~> 2.0)
|
||||
childprocess (0.5.9)
|
||||
ffi (~> 1.0, >= 1.0.11)
|
||||
climate_control (0.1.0)
|
||||
cliver (0.3.2)
|
||||
cocaine (0.5.8)
|
||||
climate_control (>= 0.0.3, < 1.0)
|
||||
coderay (1.1.1)
|
||||
coffee-rails (3.2.2)
|
||||
coffee-script (>= 2.2.0)
|
||||
@ -129,6 +132,7 @@ GEM
|
||||
treetop (~> 1.4.8)
|
||||
method_source (0.8.2)
|
||||
mime-types (1.25.1)
|
||||
mimemagic (0.3.0)
|
||||
mini_portile2 (2.0.0)
|
||||
momentjs-rails (2.15.1)
|
||||
railties (>= 3.1)
|
||||
@ -148,6 +152,12 @@ GEM
|
||||
nenv (~> 0.1)
|
||||
shellany (~> 0.0)
|
||||
orm_adapter (0.0.7)
|
||||
paperclip (4.3.7)
|
||||
activemodel (>= 3.2.0)
|
||||
activesupport (>= 3.2.0)
|
||||
cocaine (~> 0.5.5)
|
||||
mime-types
|
||||
mimemagic (= 0.3.0)
|
||||
pg (0.17.1)
|
||||
poltergeist (1.5.1)
|
||||
capybara (~> 2.1)
|
||||
@ -261,6 +271,7 @@ DEPENDENCIES
|
||||
netzke-basepack (~> 0.8.0)
|
||||
netzke-cancan
|
||||
netzke-core (~> 0.8.0)
|
||||
paperclip (~> 4.3)
|
||||
pg (~> 0.17.1)
|
||||
poltergeist (~> 1.5.0)
|
||||
pry (~> 0.9.8)
|
||||
|
@ -1,4 +1,6 @@
|
||||
class User < ActiveRecord::Base
|
||||
MAX_AVATAR_SIZE_KB = 1024
|
||||
|
||||
acts_as_loggable
|
||||
# Include default devise modules. Others available are:
|
||||
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
|
||||
@ -8,7 +10,7 @@ class User < ActiveRecord::Base
|
||||
# Setup accessible (or protected) attributes for your model
|
||||
attr_accessible :email, :password, :password_confirmation, :remember_me,
|
||||
:first_name, :last_name, :bike_id,
|
||||
:user_profiles_attributes, :username
|
||||
:user_profiles_attributes, :username, :avatar
|
||||
|
||||
has_many :transactions, as: :customer
|
||||
has_many :transaction_logs, through: :transactions, source: :logs
|
||||
@ -20,11 +22,18 @@ class User < ActiveRecord::Base
|
||||
|
||||
belongs_to :bike
|
||||
|
||||
has_attached_file :avatar, :styles => {:thumb => '100x100>'}
|
||||
|
||||
default_scope order('username ASC')
|
||||
|
||||
validates :first_name, :presence => true
|
||||
validates :last_name, :presence => true
|
||||
|
||||
validates_attachment :avatar, :content_type => {:content_type => %w{ image/jpeg image/gif image/png }},
|
||||
:file_name => {:matches => [/png\Z/, /jpe?g\Z/, /gif\Z/]},
|
||||
:size => {:in => 0..MAX_AVATAR_SIZE_KB.kilobytes}
|
||||
|
||||
|
||||
def to_s
|
||||
"#{first_name} #{last_name}"
|
||||
end
|
||||
|
@ -23,6 +23,12 @@
|
||||
= f.fields_for :user_profiles, profile_builder do |builder|
|
||||
= render 'user_profile_fields', f: builder
|
||||
|
||||
%fieldset
|
||||
.form-group
|
||||
%label You may upload your photo to be used as an avatar
|
||||
= f.file_field :avatar
|
||||
.help-block #{User::MAX_AVATAR_SIZE_KB} Kb max
|
||||
|
||||
%fieldset
|
||||
.form-group
|
||||
= f.password_field :password, placeholder: 'Password', class: 'form-control'
|
||||
|
11
db/migrate/20170118110330_add_attachment_avatar_to_users.rb
Normal file
11
db/migrate/20170118110330_add_attachment_avatar_to_users.rb
Normal file
@ -0,0 +1,11 @@
|
||||
class AddAttachmentAvatarToUsers < ActiveRecord::Migration
|
||||
def self.up
|
||||
change_table :users do |t|
|
||||
t.attachment :avatar
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_attachment :users, :avatar
|
||||
end
|
||||
end
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20131019170248) do
|
||||
ActiveRecord::Schema.define(:version => 20170118110330) do
|
||||
|
||||
create_table "bike_actions", :force => true do |t|
|
||||
t.string "action", :limit => 128, :null => false
|
||||
@ -198,6 +198,10 @@ ActiveRecord::Schema.define(:version => 20131019170248) do
|
||||
t.string "first_name", :default => "", :null => false
|
||||
t.string "last_name", :default => "", :null => false
|
||||
t.string "username"
|
||||
t.string "avatar_file_name"
|
||||
t.string "avatar_content_type"
|
||||
t.integer "avatar_file_size"
|
||||
t.datetime "avatar_updated_at"
|
||||
end
|
||||
|
||||
add_index "users", ["bike_id"], :name => "index_users_on_bike_id", :unique => true
|
||||
|
Loading…
x
Reference in New Issue
Block a user