Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 17 files changed
  • 0 commit comments
  • 1 contributor
View
3 app/assets/javascripts/entries.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/
View
3 app/assets/stylesheets/entries.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Entries controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
83 app/controllers/entries_controller.rb
@@ -0,0 +1,83 @@
+class EntriesController < ApplicationController
+ # GET /entries
+ # GET /entries.json
+ def index
+ @entries = Entry.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @entries }
+ end
+ end
+
+ # GET /entries/1
+ # GET /entries/1.json
+ def show
+ @entry = Entry.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @entry }
+ end
+ end
+
+ # GET /entries/new
+ # GET /entries/new.json
+ def new
+ @entry = Entry.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @entry }
+ end
+ end
+
+ # GET /entries/1/edit
+ def edit
+ @entry = Entry.find(params[:id])
+ end
+
+ # POST /entries
+ # POST /entries.json
+ def create
+ @entry = Entry.new(params[:entry])
+
+ respond_to do |format|
+ if @entry.save
+ format.html { redirect_to @entry, notice: 'Entry was successfully created.' }
+ format.json { render json: @entry, status: :created, location: @entry }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @entry.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /entries/1
+ # PUT /entries/1.json
+ def update
+ @entry = Entry.find(params[:id])
+
+ respond_to do |format|
+ if @entry.update_attributes(params[:entry])
+ format.html { redirect_to @entry, notice: 'Entry was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @entry.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /entries/1
+ # DELETE /entries/1.json
+ def destroy
+ @entry = Entry.find(params[:id])
+ @entry.destroy
+
+ respond_to do |format|
+ format.html { redirect_to entries_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
2 app/helpers/entries_helper.rb
@@ -0,0 +1,2 @@
+module EntriesHelper
+end
View
3 app/models/entry.rb
@@ -0,0 +1,3 @@
+class Entry < ActiveRecord::Base
+ attr_accessible :content, :title
+end
View
16 app/views/entries/_form.html.haml
@@ -0,0 +1,16 @@
+= form_for @entry do |f|
+ -if @entry.errors.any?
+ #error_explanation
+ %h2= "#{pluralize(@entry.errors.count, "error")} prohibited this entry from being saved:"
+ %ul
+ - @entry.errors.full_messages.each do |msg|
+ %li= msg
+
+ .field
+ = f.label :title
+ = f.text_field :title
+ .field
+ = f.label :content
+ = f.text_area :content
+ .actions
+ = f.submit 'Save'
View
7 app/views/entries/edit.html.haml
@@ -0,0 +1,7 @@
+%h1 Editing entry
+
+= render 'form'
+
+= link_to 'Show', @entry
+\|
+= link_to 'Back', entries_path
View
21 app/views/entries/index.html.haml
@@ -0,0 +1,21 @@
+%h1 Listing entries
+
+%table
+ %tr
+ %th Title
+ %th Content
+ %th
+ %th
+ %th
+
+ - @entries.each do |entry|
+ %tr
+ %td= entry.title
+ %td= entry.content
+ %td= link_to 'Show', entry
+ %td= link_to 'Edit', edit_entry_path(entry)
+ %td= link_to 'Destroy', entry, :confirm => 'Are you sure?', :method => :delete
+
+%br
+
+= link_to 'New Entry', new_entry_path
View
5 app/views/entries/new.html.haml
@@ -0,0 +1,5 @@
+%h1 New entry
+
+= render 'form'
+
+= link_to 'Back', entries_path
View
12 app/views/entries/show.html.haml
@@ -0,0 +1,12 @@
+%p#notice= notice
+
+%p
+ %b Title:
+ = @entry.title
+%p
+ %b Content:
+ = @entry.content
+
+= link_to 'Edit', edit_entry_path(@entry)
+\|
+= link_to 'Back', entries_path
View
2 config/routes.rb
@@ -1,4 +1,6 @@
BootstrapBootcamp::Application.routes.draw do
+ resources :entries
+
root to: 'welcome#index'
# The priority is based upon order of creation:
View
10 db/migrate/20120404060723_create_entries.rb
@@ -0,0 +1,10 @@
+class CreateEntries < ActiveRecord::Migration
+ def change
+ create_table :entries do |t|
+ t.string :title
+ t.text :content
+
+ t.timestamps
+ end
+ end
+end
View
23 db/schema.rb
@@ -0,0 +1,23 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20120404060723) do
+
+ create_table "entries", :force => true do |t|
+ t.string "title"
+ t.text "content"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+end
View
9 test/fixtures/entries.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ title: MyString
+ content: MyText
+
+two:
+ title: MyString
+ content: MyText
View
49 test/functional/entries_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class EntriesControllerTest < ActionController::TestCase
+ setup do
+ @entry = entries(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:entries)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create entry" do
+ assert_difference('Entry.count') do
+ post :create, entry: { content: @entry.content, title: @entry.title }
+ end
+
+ assert_redirected_to entry_path(assigns(:entry))
+ end
+
+ test "should show entry" do
+ get :show, id: @entry
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @entry
+ assert_response :success
+ end
+
+ test "should update entry" do
+ put :update, id: @entry, entry: { content: @entry.content, title: @entry.title }
+ assert_redirected_to entry_path(assigns(:entry))
+ end
+
+ test "should destroy entry" do
+ assert_difference('Entry.count', -1) do
+ delete :destroy, id: @entry
+ end
+
+ assert_redirected_to entries_path
+ end
+end
View
7 test/unit/entry_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class EntryTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
4 test/unit/helpers/entries_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class EntriesHelperTest < ActionView::TestCase
+end

No commit comments for this range

Something went wrong with that request. Please try again.