Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adicionando registrations (matricula)

  • Loading branch information...
commit 033db9d9b22e63025f892fbe70cc57d3e75dc4c6 1 parent 60395b9
@lucasmcastro lucasmcastro authored
View
2  Gemfile.lock
@@ -53,6 +53,7 @@ GEM
treetop (~> 1.4.8)
mime-types (1.18)
multi_json (1.2.0)
+ mysql2 (0.3.11)
mysql2 (0.3.11-x86-mingw32)
polyglot (0.3.3)
rack (1.4.1)
@@ -100,6 +101,7 @@ GEM
multi_json (>= 1.0.2)
PLATFORMS
+ ruby
x86-mingw32
DEPENDENCIES
View
3  app/assets/javascripts/registrations.js.coffee
@@ -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://jashkenas.github.com/coffee-script/
View
3  app/assets/stylesheets/registrations.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Registrations controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
83 app/controllers/registrations_controller.rb
@@ -0,0 +1,83 @@
+class RegistrationsController < ApplicationController
+ # GET /registrations
+ # GET /registrations.json
+ def index
+ @registrations = Registration.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render :json => @registrations }
+ end
+ end
+
+ # GET /registrations/1
+ # GET /registrations/1.json
+ def show
+ @registration = Registration.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render :json => @registration }
+ end
+ end
+
+ # GET /registrations/new
+ # GET /registrations/new.json
+ def new
+ @registration = Registration.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render :json => @registration }
+ end
+ end
+
+ # GET /registrations/1/edit
+ def edit
+ @registration = Registration.find(params[:id])
+ end
+
+ # POST /registrations
+ # POST /registrations.json
+ def create
+ @registration = Registration.new(params[:registration])
+
+ respond_to do |format|
+ if @registration.save
+ format.html { redirect_to @registration, :notice => 'Registration was successfully created.' }
+ format.json { render :json => @registration, :status => :created, :location => @registration }
+ else
+ format.html { render :action => "new" }
+ format.json { render :json => @registration.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /registrations/1
+ # PUT /registrations/1.json
+ def update
+ @registration = Registration.find(params[:id])
+
+ respond_to do |format|
+ if @registration.update_attributes(params[:registration])
+ format.html { redirect_to @registration, :notice => 'Registration was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render :action => "edit" }
+ format.json { render :json => @registration.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /registrations/1
+ # DELETE /registrations/1.json
+ def destroy
+ @registration = Registration.find(params[:id])
+ @registration.destroy
+
+ respond_to do |format|
+ format.html { redirect_to registrations_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
2  app/helpers/registrations_helper.rb
@@ -0,0 +1,2 @@
+module RegistrationsHelper
+end
View
5 app/models/course.rb
@@ -1,2 +1,7 @@
class Course < ActiveRecord::Base
+ has_many :registrations
+
+ def to_s
+ "#{self.name} (#{self.duration} horas)"
+ end
end
View
4 app/models/registration.rb
@@ -0,0 +1,4 @@
+class Registration < ActiveRecord::Base
+ belongs_to :registrable, :polymorphic => true
+ belongs_to :course
+end
View
5 app/models/student.rb
@@ -1,2 +1,7 @@
class Student < ActiveRecord::Base
+ has_many :registrations, :as => :registrable
+
+ def to_s
+ "#{self.name} <#{self.email}>"
+ end
end
View
1  app/models/teacher.rb
@@ -1,2 +1,3 @@
class Teacher < ActiveRecord::Base
+ has_many :registrations, :as => :registrable
end
View
25 app/views/registrations/_form.html.erb
@@ -0,0 +1,25 @@
+<%= form_for(@registration) do |f| %>
+ <% if @registration.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@registration.errors.count, "error") %> prohibited this registration from being saved:</h2>
+
+ <ul>
+ <% @registration.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :registrable %><br />
+ <%= f.text_field :registrable %>
+ </div>
+ <div class="field">
+ <%= f.label :course %><br />
+ <%= f.text_field :course %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
6 app/views/registrations/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing registration</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @registration %> |
+<%= link_to 'Back', registrations_path %>
View
25 app/views/registrations/index.html.erb
@@ -0,0 +1,25 @@
+<h1>Listing registrations</h1>
+
+<table>
+ <tr>
+ <th>Registrable</th>
+ <th>Course</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @registrations.each do |registration| %>
+ <tr>
+ <td><%= registration.registrable %></td>
+ <td><%= registration.course %></td>
+ <td><%= link_to 'Show', registration %></td>
+ <td><%= link_to 'Edit', edit_registration_path(registration) %></td>
+ <td><%= link_to 'Destroy', registration, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Registration', new_registration_path %>
View
5 app/views/registrations/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New registration</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', registrations_path %>
View
15 app/views/registrations/show.html.erb
@@ -0,0 +1,15 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Registrable:</b>
+ <%= @registration.registrable %>
+</p>
+
+<p>
+ <b>Course:</b>
+ <%= @registration.course %>
+</p>
+
+
+<%= link_to 'Edit', edit_registration_path(@registration) %> |
+<%= link_to 'Back', registrations_path %>
View
2  config/routes.rb
@@ -1,4 +1,6 @@
Academico::Application.routes.draw do
+ resources :registrations
+
resources :courses
resources :teachers
View
12 db/migrate/20120414142709_create_registrations.rb
@@ -0,0 +1,12 @@
+class CreateRegistrations < ActiveRecord::Migration
+ def change
+ create_table :registrations do |t|
+ t.references :registrable, :polymorphic => true
+ t.references :course
+
+ t.timestamps
+ end
+ add_index :registrations, :registrable_id
+ add_index :registrations, :course_id
+ end
+end
View
100 db/schema.rb
@@ -1,45 +1,55 @@
-# encoding: UTF-8
-# This file is auto-generated from the current state of the database. Instead
-# of editing this file, please use the migrations feature of Active Record to
-# incrementally modify your database, and then regenerate this schema definition.
-#
-# Note that this schema.rb definition is the authoritative source for your
-# database schema. If you need to create the application database on another
-# system, you should be using db:schema:load, not running all the migrations
-# from scratch. The latter is a flawed and unsustainable approach (the more migrations
-# you'll amass, the slower it'll run and the greater likelihood for issues).
-#
-# It's strongly recommended to check this file into your version control system.
-
-ActiveRecord::Schema.define(:version => 20120331195615) do
-
- create_table "courses", :force => true do |t|
- t.string "name"
- t.integer "duration"
- t.text "description"
- t.text "objectives"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
- end
-
- create_table "students", :force => true do |t|
- t.string "name"
- t.string "email"
- t.date "birth_date"
- t.string "phone"
- t.string "sex"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
- end
-
- create_table "teachers", :force => true do |t|
- t.string "name"
- t.string "email"
- t.string "phone"
- t.date "birth_date"
- t.string "sex"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
- end
-
-end
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20120414142709) do
+
+ create_table "courses", :force => true do |t|
+ t.string "name"
+ t.integer "duration"
+ t.text "description"
+ t.text "objectives"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ create_table "registrations", :force => true do |t|
+ t.integer "registrable_id"
+ t.string "registrable_type"
+ t.integer "course_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "registrations", ["course_id"], :name => "index_registrations_on_course_id"
+ add_index "registrations", ["registrable_id"], :name => "index_registrations_on_registrable_id"
+
+ create_table "students", :force => true do |t|
+ t.string "name"
+ t.string "email"
+ t.date "birth_date"
+ t.string "phone"
+ t.string "sex"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ create_table "teachers", :force => true do |t|
+ t.string "name"
+ t.string "email"
+ t.string "phone"
+ t.date "birth_date"
+ t.string "sex"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+end
View
9 test/fixtures/registrations.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ registrable:
+ course:
+
+two:
+ registrable:
+ course:
View
49 test/functional/registrations_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class RegistrationsControllerTest < ActionController::TestCase
+ setup do
+ @registration = registrations(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:registrations)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create registration" do
+ assert_difference('Registration.count') do
+ post :create, :registration => @registration.attributes
+ end
+
+ assert_redirected_to registration_path(assigns(:registration))
+ end
+
+ test "should show registration" do
+ get :show, :id => @registration
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, :id => @registration
+ assert_response :success
+ end
+
+ test "should update registration" do
+ put :update, :id => @registration, :registration => @registration.attributes
+ assert_redirected_to registration_path(assigns(:registration))
+ end
+
+ test "should destroy registration" do
+ assert_difference('Registration.count', -1) do
+ delete :destroy, :id => @registration
+ end
+
+ assert_redirected_to registrations_path
+ end
+end
View
4 test/unit/helpers/registrations_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class RegistrationsHelperTest < ActionView::TestCase
+end
View
7 test/unit/registration_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class RegistrationTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.