Skip to content

Commit

Permalink
Merge pull request #2 from codeunion/edit-content
Browse files Browse the repository at this point in the history
Users can edit content of résumé
  • Loading branch information
tannerwelsh committed Oct 30, 2014
2 parents 27a1e2b + 7d563cd commit 87f37ed
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ group :development do
gem 'dm-sqlite-adapter'
gem 'dotenv'
gem 'rerun'
gem 'better_errors'
gem 'binding_of_caller'
end

group :production do
Expand Down
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ GEM
bcrypt (3.1.9)
bcrypt-ruby (3.1.5)
bcrypt (>= 3.1.3)
better_errors (2.0.0)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
rack (>= 0.9.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
celluloid (0.16.0)
timers (~> 4.0.0)
coderay (1.1.0)
data_mapper (1.2.0)
dm-aggregates (~> 1.2.0)
dm-constraints (~> 1.2.0)
Expand All @@ -19,6 +26,7 @@ GEM
dm-validations (~> 1.2.0)
data_objects (0.10.14)
addressable (~> 2.1)
debug_inspector (0.0.2)
dm-aggregates (1.2.0)
dm-core (~> 1.2.0)
dm-constraints (1.2.0)
Expand Down Expand Up @@ -61,6 +69,7 @@ GEM
do_sqlite3 (0.10.14)
data_objects (= 0.10.14)
dotenv (1.0.2)
erubis (2.7.0)
faker (1.4.3)
i18n (~> 0.5)
fastercsv (1.5.5)
Expand Down Expand Up @@ -99,6 +108,8 @@ PLATFORMS
ruby

DEPENDENCIES
better_errors
binding_of_caller
data_mapper
dm-postgres-adapter
dm-sqlite-adapter
Expand Down
43 changes: 43 additions & 0 deletions linkedout.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
require 'sinatra'
require 'better_errors'

require_relative 'config/dotenv'
require_relative 'models'

configure :development do
use BetterErrors::Middleware
BetterErrors.application_root = File.expand_path('..', __FILE__)
end

helpers do
def default_user
@default_user ||= User.last
Expand All @@ -15,3 +21,40 @@ def default_user

erb :'resumes/show'
end

get "/resumes/edit" do
@jobs = default_user.jobs
@skills = default_user.skills

erb :'resumes/edit'
end

put "/users/edit" do
user_attrs = params[:user]

default_user.update(user_attrs)

redirect "/"
end

put "/jobs/edit" do
job_attrs = params[:job]

job_id = job_attrs.delete("id")

job = Job.get(job_id)
job.update(job_attrs)

redirect "/"
end

put "/skills/edit" do
skill_attrs = params[:skill]

skill_id = skill_attrs.delete("id")

skill = Skill.get(skill_id)
skill.update(skill_attrs)

redirect "/"
end
76 changes: 76 additions & 0 deletions views/resumes/edit.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<div class="resume">
<h3>Edit My Résumé</h3>

<section class="profile">
<form name="edit_user" action="/users/edit" method="post" accept-charset="utf-8">
<input type="hidden" name="_method" value="put">

<label for="user[name]">Name</label>
<input type="text" name="user[name]" value="<%= default_user.name %>">
<br>

<label for="user[email]">Email</label>
<input type="email" name="user[email]" value="<%= default_user.email %>">
<br>

<label for="user[phone]">Phone</label>
<input type="phone" name="user[phone]" value="<%= default_user.phone %>">
<br>

<label for="user[website]">Website</label>
<input type="url" name="user[website]" value="<%= default_user.website %>">
<br>

<label for="user[bio]">Bio</label>
<textarea name="user[bio]"><%= default_user.bio %></textarea>
<br>

<input type="submit" value="Update user">
</form>
</section>

<section class="jobs">
<h2>Jobs</h2>
<ul>
<% @jobs.each do |job| %>
<li>
<form name="edit_job" action="/jobs/edit" method="post" accept-charset="utf-8">
<input type="hidden" name="_method" value="put">

<input type="hidden" name="job[id]" value="<%= job.id %>">

<input type="text" name="job[job_title]" value="<%= job.job_title %>"> at
<input type="text" name="job[company_name]" value="<%= job.company_name %>">
<br>

<label for="job[job_description]">Job Description</label>
<textarea name="job[job_description]"><%= job.job_description %></textarea>
<br>

<input type="submit" value="Update job">
</form>
</li>
<% end %>
</ul>
</section>

<section class="skills">
<h2>Skills</h2>
<ul>
<% @skills.each do |skill| %>
<li>
<form name="edit_skill" action="/skills/edit" method="post" accept-charset="utf-8">
<input type="hidden" name="_method" value="put">

<input type="hidden" name="skill[id]" value="<%= skill.id %>">

<input type="text" name="skill[name]" value="<%= skill.name %>">
<br>

<input type="submit" value="Update skill">
</form>
</li>
<% end %>
</ul>
</section>
</div>
3 changes: 1 addition & 2 deletions views/resumes/show.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="resume">
<h3>My Résumé</h3>
<a href="/resumes/edit" title="Edit resume">Edit</a>

<section class="profile">
<h1><%= default_user.name %></h1>
Expand All @@ -10,8 +11,6 @@
</div>

<p><%= default_user.bio %></p>

<a href="/edit" title=""></a>
</section>

<section class="jobs">
Expand Down

0 comments on commit 87f37ed

Please sign in to comment.