Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

Updated Profile Pages #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,46 @@
class ProfilesController < ApplicationController
def index
@profiles = User.where(public: true)
end


def show
# include MD5 gem, should be part of standard ruby install
# require 'digest/md5'

if params[:id].nil?
@profile = current_user
else
@profile = User.find(params[:id])
end

# get the email from URL-parameters or what have you and make lowercase
email_address = current_user.email.downcase
email_address = @profile.email.downcase

# create the md5 hash
hash = Digest::MD5.hexdigest(email_address)

# compile URL which can be used in <img src="RIGHT_HERE"...
@gravatar_src = "http://www.gravatar.com/avatar/#{hash}?d=retro"
end

def edit
@profile = current_user
end

def update
@profile = current_user

if @profile.update(profile_params)
#@profile.save
redirect_to (profile_path)
else
render 'edit'
end
end

private
def profile_params
params.require(:user).permit(:first_name, :last_name, :email, :blurb, :hobbies, :projects, :contact, :public)
end

end
7 changes: 6 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
class User < ActiveRecord::Base
belongs_to :role

# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates :first_name, presence: true, length: {maximum: 255}, on: :update
validates :last_name, presence: true, length: {maximum: 255}, on: :update
validates :email, presence: true, length: {maximum: 255}
validates :contact, length: {maximum: 255}

end
5 changes: 4 additions & 1 deletion app/views/home/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
h1.page-header Dashboard
- if current_user
| Welcome #{current_user.email}
| Welcome #{current_user.first_name}
p
li
a href="/profiles" Meet the Community
64 changes: 64 additions & 0 deletions app/views/profiles/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<%= form_for current_user, url: profile_path(@profile), method: :patch do |f| %>

<% if @profile.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@profile.errors.count, "error") %> prohibited
this article from being saved:
</h2>
<ul>
<% @profile.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label "Required Fields*" %><br>
</p>

<p>
<%= f.label "First Name *" %><br>
<%= f.text_field :first_name %>
</p>

<p>
<%= f.label "Last Name *"%><br>
<%= f.text_field :last_name %>
</p>

<p>
<%= f.label "Email" %><br>
<%= f.text_field :email %>
</p>

<p>
<%= f.label "About Me" %><br>
<%= f.text_area :blurb %>
</p>

<p>
<%= f.label "My Hobbies" %><br>
<%= f.text_area :hobbies %>
</p>

<p>
<%= f.label "My Projects" %><br>
<%= f.text_area :projects %>
</p>

<p>
<%= f.label "Preferred Method of Contact" %><br>
<%= f.text_area :contact %>
</p>

<p>
<%= f.label "Check the box to Make Your Profile Public:" %>
<%= f.check_box :public %>
</p>

<p>
<%= f.submit "Update" %>
</p>

<% end %>
5 changes: 5 additions & 0 deletions app/views/profiles/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>Edit Your Profile</h1>

<%= render 'form' %>

<%= link_to 'Back' , profile_path %>
13 changes: 13 additions & 0 deletions app/views/profiles/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h1>Current Members</h1>

<table>
<tr>
<th>Name</th>
</tr>

<% @profiles.each do |profile| %>
<tr>
<td><%= link_to profile.first_name + ' ' + profile.last_name, controller: "profiles", action: "show", id: profile %></td>
</tr>
<% end %>
</table>
48 changes: 47 additions & 1 deletion app/views/profiles/show.html.slim
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@

h1.page-header Profile
= image_tag @gravatar_src, class: "gravatar"
| #{current_user.email}


p
<div class="row">
<div class="col-md-2"><strong>First Name:</strong></div>
<div class="col-md-2">#{@profile.first_name}</div>
<div class="col-md-2"><strong>Last Name:</strong></div>
<div class="col-md-2">#{@profile.last_name}</div>
<div class="col-md-1"><strong>Email:</strong></div>
<div class="col-md-3">#{@profile.email}</div>
</div>
p
p
<div class="row">
<div class="col-md-2"><strong>About Me:</strong></div>
<div class="col-md-6">#{@profile.blurb}</div>
</div>
p
<div class="row">
<div class="col-md-2"><strong>Hobbies:</strong></div>
<div class="col-md-6">#{@profile.hobbies}</div>
</div>

<div class="row">
<div class="col-md-2"><strong>Projects:</strong></div>
<div class="col-md-6">#{@profile.projects}</div>
</div>

p
p
<div class="row">
<div class="col-md-4"><strong>Preferred Method of Contact:</strong></div>
<div class="col-md-4">#{@profile.contact}</div>
</div>
p
<div class="row">
- if @profile.public
<div class="col-md-4"><strong>Privacy Preference:</strong> Viewable to Public</div>
- else
<div class="col-md-4"><strong>Privacy Preference:</strong> Private</div>
</div>

= link_to 'Back', profiles_path
p
-if current_user and @profile.id == current_user.id
= link_to 'Edit Profile', edit_profile_path
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Capacitor::Application.routes.draw do
devise_for :users
resource :profile
resources :profiles
resources :charges
resource :membership
root 'home#index'
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20150702002729_add_profile_information_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddProfileInformationToUsers < ActiveRecord::Migration
def change
add_column :users, :first_name, :string
add_column :users, :last_name, :string
add_column :users, :blurb, :text
add_column :users, :hobbies, :text
add_column :users, :projects, :text
add_column :users, :contact, :string
add_column :users, :public, :boolean
end
end
9 changes: 8 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20141024093025) do
ActiveRecord::Schema.define(version: 20150702002729) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -46,6 +46,13 @@
t.datetime "updated_at"
t.string "stripe_customer_id"
t.integer "role_id"
t.string "first_name"
t.string "last_name"
t.text "blurb"
t.text "hobbies"
t.text "projects"
t.string "contact"
t.boolean "public"
end

add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
Expand Down