added website, bio and location fields to user

This commit is contained in:
nilsding 2014-12-01 20:47:10 +01:00
parent ea0bf31ba1
commit 8b682bd52f
6 changed files with 35 additions and 3 deletions

View File

@ -10,7 +10,7 @@ class UserController < ApplicationController
def update def update
authenticate_user! 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) unless current_user.update_attributes(user_attributes)
flash[:error] = 'fork it' flash[:error] = 'fork it'
end end

View File

@ -22,10 +22,11 @@ class User < ActiveRecord::Base
has_many :smiles has_many :smiles
SCREEN_NAME_REGEX = /\A[a-zA-Z0-9_]{1,16}\z/ 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 :screen_name, presence: true, format: { with: SCREEN_NAME_REGEX }, uniqueness: { case_sensitive: false }
validates :website, format: { with: WEBSITE_REGEX }
def login=(login) def login=(login)
@login = login @login = login
@ -93,4 +94,10 @@ class User < ActiveRecord::Base
answer.smiles.each { |s| return true if s.user_id == self.id } answer.smiles.each { |s| return true if s.user_id == self.id }
false false
end end
def display_website
website.match(/https?:\/\/([A-Za-z.\-]+)\/?(?:.*)/i)[1]
rescue NoMethodError
website
end
end end

View File

@ -9,4 +9,10 @@
= f.text_field :motivation_header, label: "Motivation header" = 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' = f.submit "Save settings", class: 'btn btn-primary'

View File

@ -15,6 +15,15 @@
%p.user-admin %p.user-admin
%i.fa.fa-flask %i.fa.fa-flask
Admin 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 .row
.col-md-6.col-sm-6.col-xs-6 .col-md-6.col-sm-6.col-xs-6
%h4.entry-text#follower-count= @user.follower_count %h4.entry-text#follower-count= @user.follower_count

View File

@ -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

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -103,6 +103,9 @@ ActiveRecord::Schema.define(version: 20141130180152) do
t.integer "smiled_count", default: 0, null: false t.integer "smiled_count", default: 0, null: false
t.boolean "admin", default: false, null: false t.boolean "admin", default: false, null: false
t.string "motivation_header", default: "", 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 end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree