From 8b682bd52f75aee9bd30df65b3c2340eb1790d1e Mon Sep 17 00:00:00 2001 From: nilsding Date: Mon, 1 Dec 2014 20:47:10 +0100 Subject: [PATCH] added website, bio and location fields to user --- app/controllers/user_controller.rb | 2 +- app/models/user.rb | 9 ++++++++- app/views/user/edit.html.haml | 6 ++++++ app/views/user/show.html.haml | 9 +++++++++ db/migrate/20141201191324_add_fields_to_users.rb | 7 +++++++ db/schema.rb | 5 ++++- 6 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20141201191324_add_fields_to_users.rb diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 7a1758ce..f6826f26 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index fea7e6a6..0045c850 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/user/edit.html.haml b/app/views/user/edit.html.haml index 0cbea0c4..917fe8eb 100644 --- a/app/views/user/edit.html.haml +++ b/app/views/user/edit.html.haml @@ -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' \ No newline at end of file diff --git a/app/views/user/show.html.haml b/app/views/user/show.html.haml index 60061b95..5e96b2fd 100644 --- a/app/views/user/show.html.haml +++ b/app/views/user/show.html.haml @@ -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 diff --git a/db/migrate/20141201191324_add_fields_to_users.rb b/db/migrate/20141201191324_add_fields_to_users.rb new file mode 100644 index 00000000..d6fb9ca8 --- /dev/null +++ b/db/migrate/20141201191324_add_fields_to_users.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index b0218608..f151bbfb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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