Skip to content

Commit

Permalink
Generated scaffold for Image.
Browse files Browse the repository at this point in the history
  • Loading branch information
endymion committed Jun 7, 2012
1 parent 0a0b2ba commit f408d1c
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/images.js.coffee
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/images.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the Images controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
56 changes: 56 additions & 0 deletions app/assets/stylesheets/scaffolds.css.scss
@@ -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; } }
84 changes: 84 additions & 0 deletions app/controllers/images_controller.rb
@@ -0,0 +1,84 @@

class ImagesController < ApplicationController
# GET /images
# GET /images.json
def index
@images = Image.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @images }
end
end

# GET /images/1
# GET /images/1.json
def show
@image = Image.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @image }
end
end

# GET /images/new
# GET /images/new.json
def new
@image = Image.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @image }
end
end

# GET /images/1/edit
def edit
@image = Image.find(params[:id])
end

# POST /images
# POST /images.json
def create
@image = Image.new(params[:image])

respond_to do |format|
if @image.save
format.html { redirect_to @image, notice: 'Image was successfully created.' }
format.json { render json: @image, status: :created, location: @image }
else
format.html { render action: "new" }
format.json { render json: @image.errors, status: :unprocessable_entity }
end
end
end

# PUT /images/1
# PUT /images/1.json
def update
@image = Image.find(params[:id])

respond_to do |format|
if @image.update_attributes(params[:image])
format.html { redirect_to @image, notice: 'Image was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @image.errors, status: :unprocessable_entity }
end
end
end

# DELETE /images/1
# DELETE /images/1.json
def destroy
@image = Image.find(params[:id])
@image.destroy

respond_to do |format|
format.html { redirect_to images_url }
format.json { head :no_content }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/images_helper.rb
@@ -0,0 +1,2 @@
module ImagesHelper
end
3 changes: 3 additions & 0 deletions app/models/image.rb
@@ -0,0 +1,3 @@
class Image < ActiveRecord::Base
# attr_accessible :title, :body
end
17 changes: 17 additions & 0 deletions app/views/images/_form.html.erb
@@ -0,0 +1,17 @@
<%= form_for(@image) do |f| %>
<% if @image.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@image.errors.count, "error") %> prohibited this image from being saved:</h2>

<ul>
<% @image.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/images/edit.html.erb
@@ -0,0 +1,6 @@
<h1>Editing image</h1>

<%= render 'form' %>
<%= link_to 'Show', @image %> |
<%= link_to 'Back', images_path %>
21 changes: 21 additions & 0 deletions app/views/images/index.html.erb
@@ -0,0 +1,21 @@
<h1>Listing images</h1>

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

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

<br />

<%= link_to 'New Image', new_image_path %>
5 changes: 5 additions & 0 deletions app/views/images/new.html.erb
@@ -0,0 +1,5 @@
<h1>New image</h1>

<%= render 'form' %>
<%= link_to 'Back', images_path %>
5 changes: 5 additions & 0 deletions app/views/images/show.html.erb
@@ -0,0 +1,5 @@
<p id="notice"><%= notice %></p>


<%= link_to 'Edit', edit_image_path(@image) %> |
<%= link_to 'Back', images_path %>
2 changes: 2 additions & 0 deletions config/routes.rb
@@ -1,4 +1,6 @@
PaperclipJustInTimeResizing::Application.routes.draw do
resources :images

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

Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20120607145159_create_images.rb
@@ -0,0 +1,8 @@
class CreateImages < ActiveRecord::Migration
def change
create_table :images do |t|

t.timestamps
end
end
end
11 changes: 11 additions & 0 deletions test/fixtures/images.yml
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
49 changes: 49 additions & 0 deletions test/functional/images_controller_test.rb
@@ -0,0 +1,49 @@
require 'test_helper'

class ImagesControllerTest < ActionController::TestCase
setup do
@image = images(:one)
end

test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:images)
end

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

test "should create image" do
assert_difference('Image.count') do
post :create, image: { }
end

assert_redirected_to image_path(assigns(:image))
end

test "should show image" do
get :show, id: @image
assert_response :success
end

test "should get edit" do
get :edit, id: @image
assert_response :success
end

test "should update image" do
put :update, id: @image, image: { }
assert_redirected_to image_path(assigns(:image))
end

test "should destroy image" do
assert_difference('Image.count', -1) do
delete :destroy, id: @image
end

assert_redirected_to images_path
end
end
4 changes: 4 additions & 0 deletions test/unit/helpers/images_helper_test.rb
@@ -0,0 +1,4 @@
require 'test_helper'

class ImagesHelperTest < ActionView::TestCase
end
7 changes: 7 additions & 0 deletions test/unit/image_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class ImageTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit f408d1c

Please sign in to comment.