Skip to content

Commit

Permalink
Added Citation scaffold.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas Wenneker committed May 6, 2010
1 parent 7ff5698 commit fc918d6
Show file tree
Hide file tree
Showing 14 changed files with 244 additions and 0 deletions.
85 changes: 85 additions & 0 deletions app/controllers/citations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
class CitationsController < ApplicationController
# GET /citations
# GET /citations.xml
def index
@citations = Citation.all

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @citations }
end
end

# GET /citations/1
# GET /citations/1.xml
def show
@citation = Citation.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @citation }
end
end

# GET /citations/new
# GET /citations/new.xml
def new
@citation = Citation.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @citation }
end
end

# GET /citations/1/edit
def edit
@citation = Citation.find(params[:id])
end

# POST /citations
# POST /citations.xml
def create
@citation = Citation.new(params[:citation])

respond_to do |format|
if @citation.save
flash[:notice] = 'Citation was successfully created.'
format.html { redirect_to(@citation) }
format.xml { render :xml => @citation, :status => :created, :location => @citation }
else
format.html { render :action => "new" }
format.xml { render :xml => @citation.errors, :status => :unprocessable_entity }
end
end
end

# PUT /citations/1
# PUT /citations/1.xml
def update
@citation = Citation.find(params[:id])

respond_to do |format|
if @citation.update_attributes(params[:citation])
flash[:notice] = 'Citation was successfully updated.'
format.html { redirect_to(@citation) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @citation.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /citations/1
# DELETE /citations/1.xml
def destroy
@citation = Citation.find(params[:id])
@citation.destroy

respond_to do |format|
format.html { redirect_to(citations_url) }
format.xml { head :ok }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/citations_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CitationsHelper
end
2 changes: 2 additions & 0 deletions app/models/citation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Citation < ActiveRecord::Base
end
16 changes: 16 additions & 0 deletions app/views/citations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h1>Editing citation</h1>

<% form_for(@citation) do |f| %>
<%= f.error_messages %>

<p>
<%= f.label :citation %><br />
<%= f.text_area :citation %>
</p>
<p>
<%= f.submit 'Update' %>
</p>
<% end %>

<%= link_to 'Show', @citation %> |
<%= link_to 'Back', citations_path %>
20 changes: 20 additions & 0 deletions app/views/citations/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<h1>Listing citations</h1>

<table>
<tr>
<th>Citation</th>
</tr>

<% @citations.each do |citation| %>
<tr>
<td><%=h citation.citation %></td>
<td><%= link_to 'Show', citation %></td>
<td><%= link_to 'Edit', edit_citation_path(citation) %></td>
<td><%= link_to 'Destroy', citation, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New citation', new_citation_path %>
15 changes: 15 additions & 0 deletions app/views/citations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h1>New citation</h1>

<% form_for(@citation) do |f| %>
<%= f.error_messages %>

<p>
<%= f.label :citation %><br />
<%= f.text_area :citation %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>

<%= link_to 'Back', citations_path %>
8 changes: 8 additions & 0 deletions app/views/citations/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p>
<b>Citation:</b>
<%=h @citation.citation %>
</p>


<%= link_to 'Edit', edit_citation_path(@citation) %> |
<%= link_to 'Back', citations_path %>
17 changes: 17 additions & 0 deletions app/views/layouts/citations.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Citations: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>

<p style="color: green"><%= flash[:notice] %></p>

<%= yield %>

</body>
</html>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ActionController::Routing::Routes.draw do |map|
map.resources :citations

map.resources :evaluations

map.resources :evaluation_citations
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20100506192212_create_citations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateCitations < ActiveRecord::Migration
def self.up
create_table :citations do |t|
t.text :citation

t.timestamps
end
end

def self.down
drop_table :citations
end
end
7 changes: 7 additions & 0 deletions test/fixtures/citations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
citation: MyText

two:
citation: MyText
45 changes: 45 additions & 0 deletions test/functional/citations_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'test_helper'

class CitationsControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:citations)
end

test "should get new" do
get :new
assert_response :success
end

test "should create citation" do
assert_difference('Citation.count') do
post :create, :citation => { }
end

assert_redirected_to citation_path(assigns(:citation))
end

test "should show citation" do
get :show, :id => citations(:one).to_param
assert_response :success
end

test "should get edit" do
get :edit, :id => citations(:one).to_param
assert_response :success
end

test "should update citation" do
put :update, :id => citations(:one).to_param, :citation => { }
assert_redirected_to citation_path(assigns(:citation))
end

test "should destroy citation" do
assert_difference('Citation.count', -1) do
delete :destroy, :id => citations(:one).to_param
end

assert_redirected_to citations_path
end
end
8 changes: 8 additions & 0 deletions test/unit/citation_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class CitationTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
4 changes: 4 additions & 0 deletions test/unit/helpers/citations_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test_helper'

class CitationsHelperTest < ActionView::TestCase
end

0 comments on commit fc918d6

Please sign in to comment.