Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adicionando registrations (matricula)
- Loading branch information
1 parent
60395b9
commit 033db9d
Showing
21 changed files
with
322 additions
and
45 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 |
---|---|---|
@@ -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/ |
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,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/ |
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,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 |
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,2 @@ | ||
module RegistrationsHelper | ||
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,2 +1,7 @@ | ||
class Course < ActiveRecord::Base | ||
has_many :registrations | ||
|
||
def to_s | ||
"#{self.name} (#{self.duration} horas)" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Registration < ActiveRecord::Base | ||
belongs_to :registrable, :polymorphic => true | ||
belongs_to :course | ||
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,2 +1,7 @@ | ||
class Student < ActiveRecord::Base | ||
has_many :registrations, :as => :registrable | ||
|
||
def to_s | ||
"#{self.name} <#{self.email}>" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
class Teacher < ActiveRecord::Base | ||
has_many :registrations, :as => :registrable | ||
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 |
---|---|---|
@@ -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 %> |
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,6 @@ | ||
<h1>Editing registration</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Show', @registration %> | | ||
<%= link_to 'Back', registrations_path %> |
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,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 %> |
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,5 @@ | ||
<h1>New registration</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Back', registrations_path %> |
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,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 %> |
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,4 +1,6 @@ | ||
Academico::Application.routes.draw do | ||
resources :registrations | ||
|
||
resources :courses | ||
|
||
resources :teachers | ||
|
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,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 |
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,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 |
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/Fixtures.html | ||
|
||
one: | ||
registrable: | ||
course: | ||
|
||
two: | ||
registrable: | ||
course: |
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,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 |
Oops, something went wrong.