Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skills and SkillHoldings MVC #18

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3eeec89
initial local commit
May 22, 2012
31c9e31
Merge branch 'master' of git://github.com/bvmake/WhosGotWhat
May 22, 2012
468cb6e
Added tool fields
Jun 5, 2012
52cc992
Merge branch 'master' of git://github.com/bvmake/WhosGotWhat
Jun 5, 2012
7c61de2
Missing label in electric check_box
Jun 5, 2012
cdbb2f6
Make attributes accessible, remove null restriction on Tool.owner_id
Jun 5, 2012
6dbda51
http://localhost:3000/tools => Shows a list of tool names and options.
Jun 12, 2012
19f908c
Show tools page can show tool info.
Jun 12, 2012
11f0239
Merge branch 'master' of https://github.com/brundage/WhosGotWhat
Jun 12, 2012
19ba4f5
Validates tool voltage if electric is true
Jun 12, 2012
ac7ccb4
Merge branch 'master' of git://github.com/bvmake/WhosGotWhat
Jun 26, 2012
c8f9975
Skills, Skill_Holdings MVC, db migration.
Jun 26, 2012
3b9d708
Fixed string display of skill level in index.
Jun 26, 2012
e913b31
Added link to Skills owned by current_user and Tools index on the das…
Jun 27, 2012
6783fc7
CSS formatting for Skills entry and display.
Jul 15, 2012
43f3ab6
My attempt at CSS sticky footers.
Jul 15, 2012
d445ead
Initial app logo and playing with javascript.
Jul 22, 2012
6627ed4
Initial logo does not show up in Google Chrome due to some script whi…
Jul 22, 2012
c2148c3
favicon edits
Jul 22, 2012
7143dd9
Format dashboard, add template to link all Skills and User Tools, cle…
Jul 22, 2012
64a414b
Moved CSS to app/assests/styleshheets folder
Jul 22, 2012
e5b55c0
Dashboard redirect if not logged in.
Jul 22, 2012
d8936d0
minor
Jul 23, 2012
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
18 changes: 18 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>WhosGotWhat</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.aptana.ide.core.unifiedBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.radrails.rails.core.railsnature</nature>
<nature>com.aptana.ruby.core.rubynature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions app/assets/javascripts/skill_holdings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
2 changes: 2 additions & 0 deletions app/assets/javascripts/skills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
33 changes: 33 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,36 @@
*= require_self
*= require_tree .
*/

table {
font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
font-size: 12px;
background: #CCCCCC;
margin: 40px;
width: 480px;
border-collapse: collapse;
text-align: left;
border-top: 4px solid #aabcfe;
border-bottom: 4px solid #aabcfe;
}
th {
font-size: 13px;
font-weight: normal;
padding: 8px;
background: #b9c9fe;
color: #039;
}
td {
padding: 8px;
background: #e8edff;
border-bottom: 1px solid #fff;
color: #669;
border-top: 1px solid #aabcfe;
}
tr:hover td{
background: #d0dafd;
color: #339;
}
h1 {
margin-left: 20px
}
56 changes: 56 additions & 0 deletions app/assets/stylesheets/scaffolds.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px; }

p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px; }

pre {
background-color: #eee;
padding: 10px;
font-size: 11px; }

a {
color: #000;
&:visited {
color: #666; }
&:hover {
color: #fff;
background-color: #000; } }

div {
&.field, &.actions {
margin-bottom: 10px; } }

#notice {
color: green; }

.field_with_errors {
padding: 2px;
background-color: red;
display: table; }

#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff; }
ul li {
font-size: 12px;
list-style: square; } }
3 changes: 3 additions & 0 deletions app/assets/stylesheets/skill_holdings.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the skill_holdings controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/skills.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the skills controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/tools.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the tools controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
42 changes: 42 additions & 0 deletions app/controllers/skill_holdings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class SkillHoldingsController < ApplicationController

def create
@skill_holding = current_user.skill_holdings.build(params[:skill_holding])

if @skill_holding.save
redirect_to user_skill_holdings_url(current_user.id)
else
# render :action => "new"
render action: "new"
end
end

def destroy
@skill_holding = current_user.skill_holdings.find(params[:id])
@skill_holding.destroy
redirect_to user_skill_holdings_url(current_user.id)
end

def edit
@skill_holding = current_user.skill_holdings.find(params[:id])
end

def index
@skill_holdings = current_user.skill_holdings
end

def new
@skill_holding = current_user.skill_holdings.build
end

def update
@skill_holding = current_user.skill_holdings.find(params[:id])

if @skill_holding.update_attributes(params[:skill_holding])
redirect_to user_skill_holdings_url(current_user.id)
else
render action: "edit"
end
end

end
83 changes: 83 additions & 0 deletions app/controllers/skills_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
class SkillsController < ApplicationController
# GET /skills
# GET /skills.json
def index
@skills = Skill.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @skills }
end
end

# GET /skills/1
# GET /skills/1.json
def show
@skill = Skill.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @skill }
end
end

# GET /skills/new
# GET /skills/new.json
def new
@skill = Skill.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @skill }
end
end

# GET /skills/1/edit
def edit
@skill = Skill.find(params[:id])
end

# POST /skills
# POST /skills.json
def create
@skill = Skill.new(params[:skill])

respond_to do |format|
if @skill.save
format.html { redirect_to @skill, notice: 'Skill was successfully created.' }
format.json { render json: @skill, status: :created, location: @skill }
else
format.html { render action: "new" }
format.json { render json: @skill.errors, status: :unprocessable_entity }
end
end
end

# PUT /skills/1
# PUT /skills/1.json
def update
@skill = Skill.find(params[:id])

respond_to do |format|
if @skill.update_attributes(params[:skill])
format.html { redirect_to @skill, notice: 'Skill was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @skill.errors, status: :unprocessable_entity }
end
end
end

# DELETE /skills/1
# DELETE /skills/1.json
def destroy
@skill = Skill.find(params[:id])
@skill.destroy

respond_to do |format|
format.html { redirect_to skills_url }
format.json { head :no_content }
end
end
end
83 changes: 83 additions & 0 deletions app/controllers/tools_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
class ToolsController < ApplicationController
# GET /tools
# GET /tools.json
def index
@tools = Tool.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @tools }
end
end

# GET /tools/1
# GET /tools/1.json
def show
@tool = Tool.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @tool }
end
end

# GET /tools/new
# GET /tools/new.json
def new
@tool = Tool.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @tool }
end
end

# GET /tools/1/edit
def edit
@tool = Tool.find(params[:id])
end

# POST /tools
# POST /tools.json
def create
@tool = Tool.new(params[:tool])

respond_to do |format|
if @tool.save
format.html { redirect_to @tool, notice: 'Tool was successfully created.' }
format.json { render json: @tool, status: :created, location: @tool }
else
format.html { render action: "new" }
format.json { render json: @tool.errors, status: :unprocessable_entity }
end
end
end

# PUT /tools/1
# PUT /tools/1.json
def update
@tool = Tool.find(params[:id])

respond_to do |format|
if @tool.update_attributes(params[:tool])
format.html { redirect_to @tool, notice: 'Tool was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @tool.errors, status: :unprocessable_entity }
end
end
end

# DELETE /tools/1
# DELETE /tools/1.json
def destroy
@tool = Tool.find(params[:id])
@tool.destroy

respond_to do |format|
format.html { redirect_to tools_url }
format.json { head :no_content }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/skill_holdings_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SkillHoldingsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/skills_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SkillsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/tools_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ToolsHelper
end
8 changes: 8 additions & 0 deletions app/models/skill.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Skill < ActiveRecord::Base

has_many :skill_holdings
has_many :users, :through => :skill_holdings

validates :name, :presence => true, :length => {:maximum => 60}, :uniqueness => true

end
28 changes: 28 additions & 0 deletions app/models/skill_holding.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class SkillHolding < ActiveRecord::Base

attr_accessible :level, :name

belongs_to :user
belongs_to :skill

validates :level, :numericality => {:minimum => 0, :maximum => 4}
validates :user_id, :presence => true
validates :skill_id, :presence => true

SKILL_LEVELS = ["Interested in", "Novice", "Intermediate", "Experienced" , "Guru"]

def level_name
level && SKILL_LEVELS[level]
end

def name
skill && skill.name
end

def name=(skill_name)
self.skill = Skill.find_or_create_by_name(skill_name)
save
return name
end

end
7 changes: 7 additions & 0 deletions app/models/tool.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Tool < ActiveRecord::Base
# attr_accessible :title, :body
attr_accessible :name, :electric, :volts
validates :name, :presence => true
validates :volts, :numericality => {:greater_than => 0}, :if => Proc.new{|tool| tool.electric?}

end
Loading