Permalink
Browse files

added a default controller

  • Loading branch information...
bangline committed Nov 18, 2011
1 parent 0c91a9b commit 967aff3912abd7c3bb978cc129b7a1625c26cac8
@@ -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/
@@ -0,0 +1,3 @@
+// Place all the styles related to the Homes controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,56 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px; }
+
+a {
+ color: #000;
+ &:visited {
+ color: #666; }
+ &:hover {
+ color: #fff;
+ background-color: #000; } }
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px; } }
+
+#notice {
+ color: green; }
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table; }
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff; }
+ ul li {
+ font-size: 12px;
+ list-style: square; } }
@@ -0,0 +1,83 @@
+class HomesController < ApplicationController
+ # GET /homes
+ # GET /homes.json
+ def index
+ @homes = Home.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @homes }
+ end
+ end
+
+ # GET /homes/1
+ # GET /homes/1.json
+ def show
+ @home = Home.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @home }
+ end
+ end
+
+ # GET /homes/new
+ # GET /homes/new.json
+ def new
+ @home = Home.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @home }
+ end
+ end
+
+ # GET /homes/1/edit
+ def edit
+ @home = Home.find(params[:id])
+ end
+
+ # POST /homes
+ # POST /homes.json
+ def create
+ @home = Home.new(params[:home])
+
+ respond_to do |format|
+ if @home.save
+ format.html { redirect_to @home, notice: 'Home was successfully created.' }
+ format.json { render json: @home, status: :created, location: @home }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @home.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /homes/1
+ # PUT /homes/1.json
+ def update
+ @home = Home.find(params[:id])
+
+ respond_to do |format|
+ if @home.update_attributes(params[:home])
+ format.html { redirect_to @home, notice: 'Home was successfully updated.' }
+ format.json { head :ok }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @home.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /homes/1
+ # DELETE /homes/1.json
+ def destroy
+ @home = Home.find(params[:id])
+ @home.destroy
+
+ respond_to do |format|
+ format.html { redirect_to homes_url }
+ format.json { head :ok }
+ end
+ end
+end
@@ -0,0 +1,2 @@
+module HomesHelper
+end
View
@@ -0,0 +1,2 @@
+class Home < ActiveRecord::Base
+end
@@ -0,0 +1,21 @@
+<%= form_for(@home) do |f| %>
+ <% if @home.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@home.errors.count, "error") %> prohibited this home from being saved:</h2>
+
+ <ul>
+ <% @home.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :message %><br />
+ <%= f.text_field :message %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing home</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @home %> |
+<%= link_to 'Back', homes_path %>
@@ -0,0 +1,23 @@
+<h1>Listing homes</h1>
+
+<table>
+ <tr>
+ <th>Message</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @homes.each do |home| %>
+ <tr>
+ <td><%= home.message %></td>
+ <td><%= link_to 'Show', home %></td>
+ <td><%= link_to 'Edit', edit_home_path(home) %></td>
+ <td><%= link_to 'Destroy', home, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Home', new_home_path %>
@@ -0,0 +1,5 @@
+<h1>New home</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', homes_path %>
@@ -0,0 +1,10 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Message:</b>
+ <%= @home.message %>
+</p>
+
+
+<%= link_to 'Edit', edit_home_path(@home) %> |
+<%= link_to 'Back', homes_path %>
View
@@ -45,4 +45,13 @@
end
end
+namespace :my_tasks do
+
+ task :remove_index do
+ run "rm #{current_path}/public/index.html"
+ end
+
+end
+
after "deploy", "deploy:trust_rvmrc"
+after "my_tasks", "deploy:restart"
View
@@ -1,4 +1,6 @@
CapistranoDemo::Application.routes.draw do
+ resources :homes
+
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -48,7 +50,7 @@
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
- # root :to => 'welcome#index'
+ root :to => 'homes#index'
# See how all your routes lay out with "rake routes"
@@ -0,0 +1,9 @@
+class CreateHomes < ActiveRecord::Migration
+ def change
+ create_table :homes do |t|
+ t.string :message
+
+ t.timestamps
+ end
+ end
+end
View
@@ -0,0 +1,7 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ message: MyString
+
+two:
+ message: MyString
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class HomesControllerTest < ActionController::TestCase
+ setup do
+ @home = homes(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:homes)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create home" do
+ assert_difference('Home.count') do
+ post :create, home: @home.attributes
+ end
+
+ assert_redirected_to home_path(assigns(:home))
+ end
+
+ test "should show home" do
+ get :show, id: @home.to_param
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @home.to_param
+ assert_response :success
+ end
+
+ test "should update home" do
+ put :update, id: @home.to_param, home: @home.attributes
+ assert_redirected_to home_path(assigns(:home))
+ end
+
+ test "should destroy home" do
+ assert_difference('Home.count', -1) do
+ delete :destroy, id: @home.to_param
+ end
+
+ assert_redirected_to homes_path
+ end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class HomesHelperTest < ActionView::TestCase
+end
View
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class HomeTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit 967aff3

Please sign in to comment.