-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the relationship between users and projects and add a fix to the …
…footer
- Loading branch information
1 parent
a7c5c6f
commit badd1d1
Showing
15 changed files
with
138 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |