Skip to content

Commit

Permalink
Add Records and a first attempt of view to them
Browse files Browse the repository at this point in the history
  • Loading branch information
tamararivera committed Dec 13, 2013
1 parent 36ab6ee commit 9d7bbb7
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 18 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/records.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/records.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Records controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
6 changes: 6 additions & 0 deletions app/controllers/records_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RecordsController < ApplicationController
def index
@project = Project.find(params[:id])
@records = @project.records
end
end
6 changes: 3 additions & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create
@user = User.new(user_params)
if @user.save
sign_in @user
flash[:success] = "Welcome to the Sample App!"
flash[:success] = "¡Bienvenido a Pinkunozo!"
redirect_to @user
else
render 'new'
Expand All @@ -26,15 +26,15 @@ def edit
end
def update
if @user.update_attributes(user_params)
flash[:success] = "Profile updated"
flash[:success] = "Su perfil se ha actualizado con éxito"
redirect_to @user
else
render 'edit'
end
end
def destroy
User.find(params[:id]).destroy
flash[:success] = "User deleted."
flash[:success] = "Usuario eliminado"
redirect_to users_url
end

Expand Down
2 changes: 2 additions & 0 deletions app/helpers/records_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module RecordsHelper
end
2 changes: 2 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class Project < ActiveRecord::Base
has_many :user_projects, dependent: :destroy
has_many :users, through: :user_projects

has_many :records

def add_user!(user)
user_projects.create!(user_id: user.id)
Expand Down
4 changes: 4 additions & 0 deletions app/models/record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Record < ActiveRecord::Base
belongs_to :project
belongs_to :secretary, class_name: "User"
end
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
class User < ActiveRecord::Base
has_many :user_projects, dependent: :destroy
has_many :projects, through: :user_projects

has_many :records

has_secure_password

before_save { |user| user.email = email.downcase }
Expand Down
22 changes: 12 additions & 10 deletions app/views/projects/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<% provide(:title, @project.name) %>
<h1><%= @project.name %></h1>
<p>
<%= @project.description %>
</p>
<div class="btn-group btn-group-justified">
<%= link_to "Actas", "#", class: "btn btn-default" %>
<%= link_to "Libro de acuerdos", "#", class: "btn btn-default" %>
<%= link_to "Síntesis díalogica", "#", class: "btn btn-default" %>
<%= link_to "Acciones en curso", "#", class: "btn btn-default" %>
<%= link_to "Reportes de gestión", "#", class: "btn btn-default" %>
<div>
<h1><%= @project.name %></h1>
<p>
<%= @project.description %>
</p>
<div class="btn-group btn-group-justified">
<%= link_to "Actas", records_path(@project.id), class: "btn btn-default" %>
<%= link_to "Libro de acuerdos", "#", class: "btn btn-default" %>
<%= link_to "Síntesis díalogica", "#", class: "btn btn-default" %>
<%= link_to "Acciones en curso", "#", class: "btn btn-default" %>
<%= link_to "Reportes de gestión", "#", class: "btn btn-default" %>
</div>
</div>
6 changes: 2 additions & 4 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<div>
<%= render 'projects/header' %>
<div>
holi
</div>
<div>
<div>holi</div>
</div>
5 changes: 5 additions & 0 deletions app/views/records/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% provide(:title, 'Actas del proyecto ' + @project.name) %>
<div>
<%= render 'projects/header' %>
<div>holiwi</div>
</div>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
match '/help', to: 'static_pages#help', via: :get
match '/about', to: 'static_pages#about', via: :get

match '/projects/:id/records', to: 'records#index', via: :get, as: :records

# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20131212202307_create_records.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateRecords < ActiveRecord::Migration
def change
create_table :records do |t|
t.integer :project_id
t.integer :secretary_id
t.date :date

t.timestamps
end
add_index :records, [:project_id, :date], unique: true
end
end
12 changes: 11 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: 20131210150951) do
ActiveRecord::Schema.define(version: 20131212202307) do

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

create_table "records", force: true do |t|
t.integer "project_id"
t.integer "secretary_id"
t.date "date"
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "records", ["project_id", "date"], name: "index_records_on_project_id_and_date", unique: true

create_table "user_projects", force: true do |t|
t.integer "user_id"
t.integer "project_id"
Expand Down
7 changes: 7 additions & 0 deletions test/controllers/records_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class RecordsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
9 changes: 9 additions & 0 deletions test/fixtures/records.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:
project_id: 1
secretary_id: 1

two:
project_id: 1
secretary_id: 1
4 changes: 4 additions & 0 deletions test/helpers/records_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test_helper'

class RecordsHelperTest < ActionView::TestCase
end
7 changes: 7 additions & 0 deletions test/models/record_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

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

0 comments on commit 9d7bbb7

Please sign in to comment.