Permalink
Browse files

Generated scaffold for Image.

  • Loading branch information...
endymion committed Jun 7, 2012
1 parent 0a0b2ba commit f408d1ccf83b70200e8f262fa95d6c7bef8e4cfc
@@ -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 Images 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,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
@@ -0,0 +1,2 @@
module ImagesHelper
end
@@ -0,0 +1,3 @@
class Image < ActiveRecord::Base
# attr_accessible :title, :body
end
@@ -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 %>
@@ -0,0 +1,6 @@
<h1>Editing image</h1>

<%= render 'form' %>

<%= link_to 'Show', @image %> |
<%= link_to 'Back', images_path %>
@@ -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 %>
@@ -0,0 +1,5 @@
<h1>New image</h1>

<%= render 'form' %>

<%= link_to 'Back', images_path %>
@@ -0,0 +1,5 @@
<p id="notice"><%= notice %></p>


<%= link_to 'Edit', edit_image_path(@image) %> |
<%= link_to 'Back', images_path %>
@@ -1,4 +1,6 @@
PaperclipJustInTimeResizing::Application.routes.draw do
resources :images

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

@@ -0,0 +1,8 @@
class CreateImages < ActiveRecord::Migration
def change
create_table :images do |t|

t.timestamps
end
end
end
@@ -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
@@ -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
@@ -0,0 +1,4 @@
require 'test_helper'

class ImagesHelperTest < ActionView::TestCase
end
@@ -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.