Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Commit

Permalink
Generated post scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenebolshakov committed Apr 20, 2009
1 parent 4db7be5 commit 15b9ba3
Show file tree
Hide file tree
Showing 18 changed files with 316 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.swp
*log/*
*tmp/*
*log
*tmp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base

# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery # :secret => 'eef9809d5dfaa58f395554078e543826'
protect_from_forgery # :secret => 'f283b68afbddc9859ca571708eb6e0ad'

# See ActionController::Base for details
# Uncomment this to filter the contents of submitted sensitive data parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
class PostsController < ApplicationController
# GET /posts
# GET /posts.xml
def index
@posts = Post.find(:all)

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

# GET /posts/1
# GET /posts/1.xml
def show
@post = Post.find(params[:id])

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

# GET /posts/new
# GET /posts/new.xml
def new
@post = Post.new

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

# GET /posts/1/edit
def edit
@post = Post.find(params[:id])
end

# POST /posts
# POST /posts.xml
def create
@post = Post.new(params[:post])

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

# PUT /posts/1
# PUT /posts/1.xml
def update
@post = Post.find(params[:id])

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

# DELETE /posts/1
# DELETE /posts/1.xml
def destroy
@post = Post.find(params[:id])
@post.destroy

respond_to do |format|
format.html { redirect_to(posts_url) }
format.xml { head :ok }
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module PostsHelper
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Post < ActiveRecord::Base
end
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>Posts: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>

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

<%= yield %>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<h1>Editing post</h1>

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

<p>
<%= f.label :title %><br />
<%= f.text_field :title %>
</p>
<p>
<%= f.label :body %><br />
<%= f.text_area :body %>
</p>
<p>
<%= f.submit "Update" %>
</p>
<% end %>
<%= link_to 'Show', @post %> |
<%= link_to 'Back', posts_path %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<h1>Listing posts</h1>

<table>
<tr>
<th>Title</th>
<th>Body</th>
</tr>

<% for post in @posts %>
<tr>
<td><%=h post.title %></td>
<td><%=h post.body %></td>
<td><%= link_to 'Show', post %></td>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
<td><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New post', new_post_path %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<h1>New post</h1>

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

<p>
<%= f.label :title %><br />
<%= f.text_field :title %>
</p>
<p>
<%= f.label :body %><br />
<%= f.text_area :body %>
</p>
<p>
<%= f.submit "Create" %>
</p>
<% end %>
<%= link_to 'Back', posts_path %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<p>
<b>Title:</b>
<%=h @post.title %>
</p>

<p>
<b>Body:</b>
<%=h @post.body %>
</p>


<%= link_to 'Edit', edit_post_path(@post) %> |
<%= link_to 'Back', posts_path %>
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
# no regular words or you'll be exposed to dictionary attacks.
config.action_controller.session = {
:session_key => '_integration_testing_session',
:secret => '2ccb426ee14fc4a64c5c739e82d8ef58cbb01410a126157b48c830363a4a23ddec81d63a4b016677cad50264e4848d69577610000ed1655afb12527a58edf019'
:secret => 'fef5881dd0ad295d2f2fd053c904dfbeb1f47bf025f513cfeb2fb323bfa5ea55319c41e1a42f14e6882f0589994a8915c87d19e89237516eaa53b1988ecf171d'
}

# Use the database for sessions instead of the cookie-based default,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ActionController::Routing::Routes.draw do |map|
map.resources :posts

# The priority is based upon order of creation: first created -> highest priority.

# Sample of regular route:
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreatePosts < ActiveRecord::Migration
def self.up
create_table :posts do |t|
t.string :title
t.text :body

t.timestamps
end
end

def self.down
drop_table :posts
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
body { background-color: #fff; color: #333; }

body, 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; }
a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; }

.fieldWithErrors {
padding: 2px;
background-color: red;
display: table;
}

#errorExplanation {
width: 400px;
border: 2px solid red;
padding: 7px;
padding-bottom: 12px;
margin-bottom: 20px;
background-color: #f0f0f0;
}

#errorExplanation h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
background-color: #c00;
color: #fff;
}

#errorExplanation p {
color: #333;
margin-bottom: 0;
padding: 5px;
}

#errorExplanation ul li {
font-size: 12px;
list-style: square;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
title: MyString
body: MyText

two:
title: MyString
body: MyText
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'test_helper'

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

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

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

assert_redirected_to post_path(assigns(:post))
end

test "should show post" do
get :show, :id => posts(:one).id
assert_response :success
end

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

test "should update post" do
put :update, :id => posts(:one).id, :post => { }
assert_redirected_to post_path(assigns(:post))
end

test "should destroy post" do
assert_difference('Post.count', -1) do
delete :destroy, :id => posts(:one).id
end

assert_redirected_to posts_path
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class PostTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end

0 comments on commit 15b9ba3

Please sign in to comment.