added website, bio and location fields to user
This commit is contained in:
parent
ea0bf31ba1
commit
8b682bd52f
|
@ -10,7 +10,7 @@ class UserController < ApplicationController
|
|||
|
||||
def update
|
||||
authenticate_user!
|
||||
user_attributes = params.require(:user).permit(:display_name, :motivation_header)
|
||||
user_attributes = params.require(:user).permit(:display_name, :motivation_header, :website, :location, :bio)
|
||||
unless current_user.update_attributes(user_attributes)
|
||||
flash[:error] = 'fork it'
|
||||
end
|
||||
|
|
|
@ -22,10 +22,11 @@ class User < ActiveRecord::Base
|
|||
has_many :smiles
|
||||
|
||||
SCREEN_NAME_REGEX = /\A[a-zA-Z0-9_]{1,16}\z/
|
||||
WEBSITE_REGEX = /https?:\/\/([A-Za-z.\-]+)\/?(?:.*)/i
|
||||
|
||||
validates :screen_name, presence: true, format: { with: SCREEN_NAME_REGEX }, uniqueness: { case_sensitive: false }
|
||||
|
||||
|
||||
validates :website, format: { with: WEBSITE_REGEX }
|
||||
|
||||
def login=(login)
|
||||
@login = login
|
||||
|
@ -93,4 +94,10 @@ class User < ActiveRecord::Base
|
|||
answer.smiles.each { |s| return true if s.user_id == self.id }
|
||||
false
|
||||
end
|
||||
|
||||
def display_website
|
||||
website.match(/https?:\/\/([A-Za-z.\-]+)\/?(?:.*)/i)[1]
|
||||
rescue NoMethodError
|
||||
website
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,4 +9,10 @@
|
|||
|
||||
= f.text_field :motivation_header, label: "Motivation header"
|
||||
|
||||
= f.text_field :website, label: "Website"
|
||||
|
||||
= f.text_field :location, label: "Location"
|
||||
|
||||
= f.text_area :bio, label: "Bio"
|
||||
|
||||
= f.submit "Save settings", class: 'btn btn-primary'
|
|
@ -15,6 +15,15 @@
|
|||
%p.user-admin
|
||||
%i.fa.fa-flask
|
||||
Admin
|
||||
/ TODO: make this look prettier (pixeldesu!!!!)
|
||||
- unless @user.website.blank?
|
||||
%i.fa.fa-globe
|
||||
%a{href: @user.website}= @user.display_website
|
||||
- unless @user.location.blank?
|
||||
%i.fa.fa-location-arrow
|
||||
= @user.location
|
||||
- unless @user.bio.blank?
|
||||
= @user.bio
|
||||
.row
|
||||
.col-md-6.col-sm-6.col-xs-6
|
||||
%h4.entry-text#follower-count= @user.follower_count
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
class AddFieldsToUsers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :website, :string, default: '', null: false
|
||||
add_column :users, :location, :string, default: '', null: false
|
||||
add_column :users, :bio, :text, default: '', null: false
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20141130180152) do
|
||||
ActiveRecord::Schema.define(version: 20141201191324) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -103,6 +103,9 @@ ActiveRecord::Schema.define(version: 20141130180152) do
|
|||
t.integer "smiled_count", default: 0, null: false
|
||||
t.boolean "admin", default: false, null: false
|
||||
t.string "motivation_header", default: "", null: false
|
||||
t.string "website", default: "", null: false
|
||||
t.string "location", default: "", null: false
|
||||
t.text "bio", default: "", null: false
|
||||
end
|
||||
|
||||
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
|
||||
|
|
Loading…
Reference in New Issue