Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

new documents module

  • Loading branch information...
commit c07e71316285f0c9c54a7cb590c7d1f7fb0f300d 1 parent 1fafef2
Timothy Fisher authored
85 app/controllers/documents_controller.rb
View
@@ -0,0 +1,85 @@
+class DocumentsController < ApplicationController
+ # GET /documents
+ # GET /documents.xml
+ def index
+ @documents = Document.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @documents }
+ end
+ end
+
+ # GET /documents/1
+ # GET /documents/1.xml
+ def show
+ @document = Document.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @document }
+ end
+ end
+
+ # GET /documents/new
+ # GET /documents/new.xml
+ def new
+ @document = Document.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @document }
+ end
+ end
+
+ # GET /documents/1/edit
+ def edit
+ @document = Document.find(params[:id])
+ end
+
+ # POST /documents
+ # POST /documents.xml
+ def create
+ @document = Document.new(params[:document])
+
+ respond_to do |format|
+ if @document.save
+ flash[:notice] = 'Document was successfully created.'
+ format.html { redirect_to(@document) }
+ format.xml { render :xml => @document, :status => :created, :location => @document }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @document.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /documents/1
+ # PUT /documents/1.xml
+ def update
+ @document = Document.find(params[:id])
+
+ respond_to do |format|
+ if @document.update_attributes(params[:document])
+ flash[:notice] = 'Document was successfully updated.'
+ format.html { redirect_to(@document) }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @document.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /documents/1
+ # DELETE /documents/1.xml
+ def destroy
+ @document = Document.find(params[:id])
+ @document.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(documents_url) }
+ format.xml { head :ok }
+ end
+ end
+end
2  app/helpers/documents_helper.rb
View
@@ -0,0 +1,2 @@
+module DocumentsHelper
+end
2  app/models/document.rb
View
@@ -0,0 +1,2 @@
+class Document < ActiveRecord::Base
+end
12 app/views/documents/edit.html.erb
View
@@ -0,0 +1,12 @@
+<h1>Editing document</h1>
+
+<% form_for(@document) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.submit 'Update' %>
+ </p>
+<% end %>
+
+<%= link_to 'Show', @document %> |
+<%= link_to 'Back', documents_path %>
18 app/views/documents/index.html.erb
View
@@ -0,0 +1,18 @@
+<h1>Listing documents</h1>
+
+<table>
+ <tr>
+ </tr>
+
+<% @documents.each do |document| %>
+ <tr>
+ <td><%= link_to 'Show', document %></td>
+ <td><%= link_to 'Edit', edit_document_path(document) %></td>
+ <td><%= link_to 'Destroy', document, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New document', new_document_path %>
11 app/views/documents/new.html.erb
View
@@ -0,0 +1,11 @@
+<h1>New document</h1>
+
+<% form_for(@document) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.submit 'Create' %>
+ </p>
+<% end %>
+
+<%= link_to 'Back', documents_path %>
3  app/views/documents/show.html.erb
View
@@ -0,0 +1,3 @@
+
+<%= link_to 'Edit', edit_document_path(@document) %> |
+<%= link_to 'Back', documents_path %>
22 db/migrate/20101118194823_create_documents.rb
View
@@ -0,0 +1,22 @@
+class CreateDocuments < ActiveRecord::Migration
+ def self.up
+ create_table :documents do |t|
+ t.string :document_file_name
+ t.string :document_content_type
+ t.integer :document_file_size
+ t.datetime :document_updated_at
+
+ t.integer :user_id # the user who uploaded the document
+
+ # can be associated with a group or event
+ t.integer :group_id
+ t.integer :event_id
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :documents
+ end
+end
7 test/fixtures/documents.yml
View
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
45 test/functional/documents_controller_test.rb
View
@@ -0,0 +1,45 @@
+require 'test_helper'
+
+class DocumentsControllerTest < ActionController::TestCase
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:documents)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create document" do
+ assert_difference('Document.count') do
+ post :create, :document => { }
+ end
+
+ assert_redirected_to document_path(assigns(:document))
+ end
+
+ test "should show document" do
+ get :show, :id => documents(:one).to_param
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, :id => documents(:one).to_param
+ assert_response :success
+ end
+
+ test "should update document" do
+ put :update, :id => documents(:one).to_param, :document => { }
+ assert_redirected_to document_path(assigns(:document))
+ end
+
+ test "should destroy document" do
+ assert_difference('Document.count', -1) do
+ delete :destroy, :id => documents(:one).to_param
+ end
+
+ assert_redirected_to documents_path
+ end
+end
8 test/unit/document_test.rb
View
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class DocumentTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
4 test/unit/helpers/documents_helper_test.rb
View
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class DocumentsHelperTest < ActionView::TestCase
+end
Please sign in to comment.
Something went wrong with that request. Please try again.