From f408d1ccf83b70200e8f262fa95d6c7bef8e4cfc Mon Sep 17 00:00:00 2001 From: Ryan Alyn Porter Date: Thu, 7 Jun 2012 10:52:21 -0400 Subject: [PATCH] Generated scaffold for Image. --- app/assets/javascripts/images.js.coffee | 3 + app/assets/stylesheets/images.css.scss | 3 + app/assets/stylesheets/scaffolds.css.scss | 56 +++++++++++++++ app/controllers/images_controller.rb | 84 ++++++++++++++++++++++ app/helpers/images_helper.rb | 2 + app/models/image.rb | 3 + app/views/images/_form.html.erb | 17 +++++ app/views/images/edit.html.erb | 6 ++ app/views/images/index.html.erb | 21 ++++++ app/views/images/new.html.erb | 5 ++ app/views/images/show.html.erb | 5 ++ config/routes.rb | 2 + db/migrate/20120607145159_create_images.rb | 8 +++ test/fixtures/images.yml | 11 +++ test/functional/images_controller_test.rb | 49 +++++++++++++ test/unit/helpers/images_helper_test.rb | 4 ++ test/unit/image_test.rb | 7 ++ 17 files changed, 286 insertions(+) create mode 100644 app/assets/javascripts/images.js.coffee create mode 100644 app/assets/stylesheets/images.css.scss create mode 100644 app/assets/stylesheets/scaffolds.css.scss create mode 100644 app/controllers/images_controller.rb create mode 100644 app/helpers/images_helper.rb create mode 100644 app/models/image.rb create mode 100644 app/views/images/_form.html.erb create mode 100644 app/views/images/edit.html.erb create mode 100644 app/views/images/index.html.erb create mode 100644 app/views/images/new.html.erb create mode 100644 app/views/images/show.html.erb create mode 100644 db/migrate/20120607145159_create_images.rb create mode 100644 test/fixtures/images.yml create mode 100644 test/functional/images_controller_test.rb create mode 100644 test/unit/helpers/images_helper_test.rb create mode 100644 test/unit/image_test.rb diff --git a/app/assets/javascripts/images.js.coffee b/app/assets/javascripts/images.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/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/ diff --git a/app/assets/stylesheets/images.css.scss b/app/assets/stylesheets/images.css.scss new file mode 100644 index 0000000..539c9b6 --- /dev/null +++ b/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/ diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 0000000..05188f0 --- /dev/null +++ b/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; } } diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb new file mode 100644 index 0000000..8ea0dc7 --- /dev/null +++ b/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 diff --git a/app/helpers/images_helper.rb b/app/helpers/images_helper.rb new file mode 100644 index 0000000..7b3a8bc --- /dev/null +++ b/app/helpers/images_helper.rb @@ -0,0 +1,2 @@ +module ImagesHelper +end diff --git a/app/models/image.rb b/app/models/image.rb new file mode 100644 index 0000000..491bfeb --- /dev/null +++ b/app/models/image.rb @@ -0,0 +1,3 @@ +class Image < ActiveRecord::Base + # attr_accessible :title, :body +end diff --git a/app/views/images/_form.html.erb b/app/views/images/_form.html.erb new file mode 100644 index 0000000..42ba49d --- /dev/null +++ b/app/views/images/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_for(@image) do |f| %> + <% if @image.errors.any? %> +
+

<%= pluralize(@image.errors.count, "error") %> prohibited this image from being saved:

+ + +
+ <% end %> + +
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/images/edit.html.erb b/app/views/images/edit.html.erb new file mode 100644 index 0000000..2cdb709 --- /dev/null +++ b/app/views/images/edit.html.erb @@ -0,0 +1,6 @@ +

Editing image

+ +<%= render 'form' %> + +<%= link_to 'Show', @image %> | +<%= link_to 'Back', images_path %> diff --git a/app/views/images/index.html.erb b/app/views/images/index.html.erb new file mode 100644 index 0000000..baa8540 --- /dev/null +++ b/app/views/images/index.html.erb @@ -0,0 +1,21 @@ +

Listing images

+ + + + + + + + +<% @images.each do |image| %> + + + + + +<% end %> +
<%= link_to 'Show', image %><%= link_to 'Edit', edit_image_path(image) %><%= link_to 'Destroy', image, confirm: 'Are you sure?', method: :delete %>
+ +
+ +<%= link_to 'New Image', new_image_path %> diff --git a/app/views/images/new.html.erb b/app/views/images/new.html.erb new file mode 100644 index 0000000..e46ebc7 --- /dev/null +++ b/app/views/images/new.html.erb @@ -0,0 +1,5 @@ +

New image

+ +<%= render 'form' %> + +<%= link_to 'Back', images_path %> diff --git a/app/views/images/show.html.erb b/app/views/images/show.html.erb new file mode 100644 index 0000000..7af5d4f --- /dev/null +++ b/app/views/images/show.html.erb @@ -0,0 +1,5 @@ +

<%= notice %>

+ + +<%= link_to 'Edit', edit_image_path(@image) %> | +<%= link_to 'Back', images_path %> diff --git a/config/routes.rb b/config/routes.rb index 2200bc7..107f92d 100644 --- a/config/routes.rb +++ b/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. diff --git a/db/migrate/20120607145159_create_images.rb b/db/migrate/20120607145159_create_images.rb new file mode 100644 index 0000000..61f98d8 --- /dev/null +++ b/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 diff --git a/test/fixtures/images.yml b/test/fixtures/images.yml new file mode 100644 index 0000000..c63aac0 --- /dev/null +++ b/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 diff --git a/test/functional/images_controller_test.rb b/test/functional/images_controller_test.rb new file mode 100644 index 0000000..8c4d95a --- /dev/null +++ b/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 diff --git a/test/unit/helpers/images_helper_test.rb b/test/unit/helpers/images_helper_test.rb new file mode 100644 index 0000000..f2a0cf2 --- /dev/null +++ b/test/unit/helpers/images_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class ImagesHelperTest < ActionView::TestCase +end diff --git a/test/unit/image_test.rb b/test/unit/image_test.rb new file mode 100644 index 0000000..6d2d287 --- /dev/null +++ b/test/unit/image_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ImageTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end