-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Neil Gehani
committed
Sep 17, 2013
1 parent
846b504
commit 22e9a27
Showing
20 changed files
with
233 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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://coffeescript.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
class PinsController < ApplicationController | ||
before_action :set_pin, only: [:show, :edit, :update, :destroy] | ||
|
||
# GET /pins | ||
# GET /pins.json | ||
def index | ||
@pins = Pin.all | ||
end | ||
|
||
# GET /pins/1 | ||
# GET /pins/1.json | ||
def show | ||
end | ||
|
||
# GET /pins/new | ||
def new | ||
@pin = Pin.new | ||
end | ||
|
||
# GET /pins/1/edit | ||
def edit | ||
end | ||
|
||
# POST /pins | ||
# POST /pins.json | ||
def create | ||
@pin = Pin.new(pin_params) | ||
|
||
respond_to do |format| | ||
if @pin.save | ||
format.html { redirect_to @pin, notice: 'Pin was successfully created.' } | ||
format.json { render action: 'show', status: :created, location: @pin } | ||
else | ||
format.html { render action: 'new' } | ||
format.json { render json: @pin.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /pins/1 | ||
# PATCH/PUT /pins/1.json | ||
def update | ||
respond_to do |format| | ||
if @pin.update(pin_params) | ||
format.html { redirect_to @pin, notice: 'Pin was successfully updated.' } | ||
format.json { head :no_content } | ||
else | ||
format.html { render action: 'edit' } | ||
format.json { render json: @pin.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /pins/1 | ||
# DELETE /pins/1.json | ||
def destroy | ||
@pin.destroy | ||
respond_to do |format| | ||
format.html { redirect_to pins_url } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_pin | ||
@pin = Pin.find(params[:id]) | ||
end | ||
|
||
# Never trust parameters from the scary internet, only allow the white list through. | ||
def pin_params | ||
params.require(:pin).permit(:description) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module PinsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Pin < ActiveRecord::Base | ||
attr_accessible :description | ||
|
||
validates :description, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<%= simple_form_for(@pin, html: { class: "form-horizontal"}) do |f| %> | ||
<%= f.error_notification %> | ||
|
||
<%= f.input :description, as: :text, input_html: { rows: "3" } %> | ||
|
||
<div class="form-actions"> | ||
<%= f.button :submit, class: "btn btn-primary" %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<tr> | ||
<td><%= pin.description %></td> | ||
<td><%= link_to 'Show', pin %></td> | ||
<td><%= link_to 'Edit', edit_pin_path(pin) %></td> | ||
<td><%= link_to 'Destroy', pin, method: :delete, data: { confirm: 'Are you sure?' } %></td> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing pin</h1> | ||
|
||
<%= render 'form' %> | ||
|
||
<%= link_to 'Show', @pin %> | | ||
<%= link_to 'Back', pins_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h1>Listing pins</h1> | ||
|
||
<table class="table table-striped"> | ||
<thead> | ||
<tr> | ||
<th>Description</th> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<%= render @pins %> | ||
</tbody> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New Pin', new_pin_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
json.array!(@pins) do |pin| | ||
json.extract! pin, :description | ||
json.url pin_url(pin, format: :json) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>New pin</h1> | ||
|
||
<%= render 'form' %> | ||
|
||
<%= link_to 'Back', pins_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div class="row"> | ||
<div class="span6 offset3"> | ||
<%# This puts the grey box around content below %> | ||
<div class="well"> | ||
<p> | ||
<%= @pin.description %> | ||
</p> | ||
<%= link_to 'Edit', edit_pin_path(@pin) %> | | ||
<%= link_to 'Back', pins_path %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.extract! @pin, :description, :created_at, :updated_at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreatePins < ActiveRecord::Migration | ||
def change | ||
create_table :pins do |t| | ||
t.string :description | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'test_helper' | ||
|
||
class PinsControllerTest < ActionController::TestCase | ||
setup do | ||
@pin = pins(:one) | ||
end | ||
|
||
test "should get index" do | ||
get :index | ||
assert_response :success | ||
assert_not_nil assigns(:pins) | ||
end | ||
|
||
test "should get new" do | ||
get :new | ||
assert_response :success | ||
end | ||
|
||
test "should create pin" do | ||
assert_difference('Pin.count') do | ||
post :create, pin: { description: @pin.description } | ||
end | ||
|
||
assert_redirected_to pin_path(assigns(:pin)) | ||
end | ||
|
||
test "should show pin" do | ||
get :show, id: @pin | ||
assert_response :success | ||
end | ||
|
||
test "should get edit" do | ||
get :edit, id: @pin | ||
assert_response :success | ||
end | ||
|
||
test "should update pin" do | ||
patch :update, id: @pin, pin: { description: @pin.description } | ||
assert_redirected_to pin_path(assigns(:pin)) | ||
end | ||
|
||
test "should destroy pin" do | ||
assert_difference('Pin.count', -1) do | ||
delete :destroy, id: @pin | ||
end | ||
|
||
assert_redirected_to pins_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html | ||
|
||
one: | ||
description: MyString | ||
|
||
two: | ||
description: MyString |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'test_helper' | ||
|
||
class PinsHelperTest < ActionView::TestCase | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class PinTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |