Skip to content

Commit

Permalink
Add the relationship between users and projects and add a fix to the …
Browse files Browse the repository at this point in the history
…footer
  • Loading branch information
tamararivera committed Dec 12, 2013
1 parent a7c5c6f commit badd1d1
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 60 deletions.
41 changes: 19 additions & 22 deletions app/assets/stylesheets/custom.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,26 @@ p {
}

/* footer */
html,
body {
height: 100%;
/* The html and body elements cannot have any padding or margin. */
}

footer {
margin-top: 45px;
padding-top: 5px;
border-top: 1px solid #eaeaea;
color: $gray-light;
a {
color: #555;
}
small {
float: left;
}
ul {
float: right;
list-style: none;
li {
float: left;
margin-left: 10px;
}
}
&:hover {
color: #222;
}
/* Wrapper for page content to push down footer */
#wrap {
min-height: 100%;
height: auto;
/* Negative indent footer by its height */
margin: 0 auto -60px;
/* Pad bottom by footer height */
padding: 0 0 60px;
}

/* Set the fixed height of the footer here */
#footer {
height: 60px;
background-color: #f5f5f5;
}

/* sidebar */
Expand Down
1 change: 1 addition & 0 deletions app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class StaticPagesController < ApplicationController
def home
@projects = current_user.projects
end

def help
Expand Down
5 changes: 5 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
class Project < ActiveRecord::Base
has_many :user_projects, dependent: :destroy
has_many :users, through: :user_projects

def add_user!(user)
user_projects.create!(user_id: user.id)
end
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class User < ActiveRecord::Base
has_many :user_projects, dependent: :destroy
has_many :projects, through: :user_projects
has_secure_password

before_save { |user| user.email = email.downcase }
Expand Down
7 changes: 7 additions & 0 deletions app/models/user_project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class UserProject < ActiveRecord::Base
belongs_to :user
belongs_to :project

validates :user_id, presence: true
validates :project_id, presence: true
end
20 changes: 11 additions & 9 deletions app/views/layouts/_footer.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<footer class="footer">
<nav>
<ul>
<li><%= link_to "Nosotros", about_path %></li>
<li><%= link_to "Contactanos", '#'%></li>
<li><a href="http://www.chileagil.cl/">ChileÁgil</a></li>
</ul>
</nav>
</footer>
<div id="footer">
<div class="container">
<nav>
<ul class="nav navbar-nav pull-right">
<li><%= link_to "Nosotros", about_path %></li>
<li><%= link_to "Contactanos", '#'%></li>
<li><a href="http://www.chileagil.cl/">ChileÁgil</a></li>
</ul>
</nav>
</div>
</div>
16 changes: 9 additions & 7 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
<![endif]-->
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |key, value| %>
<div class="<%= flash_class(key) %>"><%= value %></div>
<% end %>
<%= yield %>
<%= render 'layouts/footer' %>
<div id="wrap">
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |key, value| %>
<div class="<%= flash_class(key) %>"><%= value %></div>
<% end %>
<%= yield %>
</div>
</div>
<%= render 'layouts/footer' %>
</body>
</html>
8 changes: 8 additions & 0 deletions app/views/shared/_project.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="col-md-4">
<%= link_to (project) do %>
<button class= "btn btn-lg btn-default">
<span class="glyphicon glyphicon-briefcase"></span>
<%= project.name %>
</button>
<%end %>
</div>
13 changes: 11 additions & 2 deletions app/views/static_pages/home.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<div class="center hero-unit">
<%if signed_in? %>
<div class="col-md-6 col-md-offset-3">
<%if @projects.any?%>
<div class="row">
<%= render partial: 'shared/project', collection: @projects %>
</div>
<%end%>
</div>
<%else %>
<h1>Bienvenido a Pinkunozo</h1>

<%= link_to "Identificarse", signin_path, class: "btn btn-large btn-primary" %>
<%= link_to "Identificarse", signin_path, class: "btn btn-lg btn-primary" %>
<%end %>
</div>
13 changes: 13 additions & 0 deletions db/migrate/20131210150951_create_user_projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateUserProjects < ActiveRecord::Migration
def change
create_table :user_projects do |t|
t.integer :user_id
t.integer :project_id

t.timestamps
end
add_index :user_projects, :user_id
add_index :user_projects, :project_id
add_index :user_projects, [:user_id, :project_id], unique: true
end
end
13 changes: 12 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: 20131205235724) do
ActiveRecord::Schema.define(version: 20131210150951) do

create_table "projects", force: true do |t|
t.string "name"
Expand All @@ -20,6 +20,17 @@
t.datetime "updated_at"
end

create_table "user_projects", force: true do |t|
t.integer "user_id"
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "user_projects", ["project_id"], name: "index_user_projects_on_project_id"
add_index "user_projects", ["user_id", "project_id"], name: "index_user_projects_on_user_id_and_project_id", unique: true
add_index "user_projects", ["user_id"], name: "index_user_projects_on_user_id"

create_table "users", force: true do |t|
t.string "name"
t.string "email"
Expand Down
24 changes: 24 additions & 0 deletions lib/tasks/sample_projects.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
namespace :db do
desc "Fill database with sample projects"
task populate: :environment do
make_users
make_projects
end

def make_users
User.create!(name: "Tamara Rivera",
email: "[email protected]",
password: "memoria",
password_confirmation: "memoria",
admin: true)
99.times do |n|
name = Faker::Name.name
email = "example-#{n+1}@railstutorial.org"
password = "password"
User.create!(name: name,
email: email,
password: password,
password_confirmation: password)
end
end

def make_projects
Project.create!(name: "Proyecto Fondef",
description: "Este es un proyecto fabuloso")
project = Project.first
project.add_user!(User.first)
end
end
19 changes: 0 additions & 19 deletions lib/tasks/sample_users.rake

This file was deleted.

9 changes: 9 additions & 0 deletions test/fixtures/user_projects.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
user_id: 1
project_id: 1

two:
user_id: 1
project_id: 1
7 changes: 7 additions & 0 deletions test/models/user_project_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class UserProjectTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit badd1d1

Please sign in to comment.