Skip to content

Commit

Permalink
Destroy and re-add Pins Scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Gehani committed Sep 19, 2013
1 parent a1f589e commit e8edabf
Show file tree
Hide file tree
Showing 17 changed files with 260 additions and 107 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ruby '2.0.0'
gem 'rails', '4.0.0'
gem 'jquery-rails'
gem 'devise'
gem 'simple_form'
gem 'simple_form', '~> 3.0.0.rc'

group :production do
gem 'pg'
Expand Down
8 changes: 5 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ GEM
minitest (4.7.5)
multi_json (1.8.0)
orm_adapter (0.4.0)
pg (0.16.0)
pg (0.17.0)
polyglot (0.3.3)
protected_attributes (1.0.3)
activemodel (>= 4.0.0, < 5.0)
Expand Down Expand Up @@ -97,7 +97,9 @@ GEM
sdoc (0.3.20)
json (>= 1.1.3)
rdoc (~> 3.10)
simple_form (1.4.1)
simple_form (3.0.0.rc)
actionpack (>= 4.0.0.rc1, < 4.1)
activemodel (>= 4.0.0.rc1, < 4.1)
sprockets (2.10.0)
hike (~> 1.2)
multi_json (~> 1.0)
Expand Down Expand Up @@ -139,7 +141,7 @@ DEPENDENCIES
rails_12factor
sass-rails (~> 4.0.0)
sdoc
simple_form
simple_form (~> 3.0.0.rc)
sqlite3
turbolinks (= 1.1.1)
uglifier (>= 1.3.0)
3 changes: 3 additions & 0 deletions app/assets/stylesheets/pins.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Pins controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
69 changes: 69 additions & 0 deletions app/assets/stylesheets/scaffolds.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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;
}
}
8 changes: 2 additions & 6 deletions app/controllers/pins_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class PinsController < ApplicationController
before_action :set_pin, only: [:show, :edit, :update, :destroy]
before_filter :authenticate_user!, except: [:index]

# GET /pins
# GET /pins.json
Expand All @@ -15,18 +14,17 @@ def show

# GET /pins/new
def new
@pin = current_user.pins.new
@pin = Pin.new
end

# GET /pins/1/edit
def edit
@pin = current_user.pins.find(params[:id])
end

# POST /pins
# POST /pins.json
def create
@pin = current_user.pins.new(params[:pin])
@pin = Pin.new(pin_params)

respond_to do |format|
if @pin.save
Expand All @@ -42,7 +40,6 @@ def create
# PATCH/PUT /pins/1
# PATCH/PUT /pins/1.json
def update
@pin = current_user.pins.find(params[:id])
respond_to do |format|
if @pin.update(pin_params)
format.html { redirect_to @pin, notice: 'Pin was successfully updated.' }
Expand All @@ -57,7 +54,6 @@ def update
# DELETE /pins/1
# DELETE /pins/1.json
def destroy
@pin = current_user.pins.find(params[:id])
@pin.destroy
respond_to do |format|
format.html { redirect_to pins_url }
Expand Down
4 changes: 0 additions & 4 deletions app/models/pin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@ class Pin < ActiveRecord::Base
attr_accessible :description

validates :description, presence: true
validates :name, presence: true

belongs_to :user
validates :user_id, presence: true
end
2 changes: 1 addition & 1 deletion app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h2>Sign in</h2>

<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), html: { class: 'form-horizontal'}) do |f| %>
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), html: { class: "form-horizontal"}) do |f| %>

<%= f.input :email, placeholder: '[email protected]' %>
<%= f.input :password, placeholder: 'hint: no special characters' %>
Expand Down
10 changes: 5 additions & 5 deletions app/views/pins/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<%= simple_form_for(@pin, html: { class: "form-horizontal"}) do |f| %>
<%= simple_form_for(@pin, html: {class: "form_horizontal"}) do |f| %>
<%= f.error_notification %>

<%= f.input :description, as: :text, input_html: { rows: "3" } %>

<%= f.input :description, as: :text, input_html: { rows: "3" } %>
<div class="form-actions">
<%= f.button :submit, class: "btn btn-primary" %>
<%= f.button :submit, class: "btn btn-primary" %>
</div>
<% end %>
<% end %>
12 changes: 6 additions & 6 deletions app/views/pins/_pin.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<tr>
<% @pins.each do |pin| %>
<tr>
<td><%= pin.description %></td>
<td><%= link_to 'Show', pin %></td>
<% if current_user == pin.user %>
<td><%= link_to 'Edit', edit_pin_path(pin) %></td>
<td><%= link_to 'Destroy', pin, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<% end %>
</tr>
<td><%= link_to 'Edit', edit_pin_path(pin) %></td>
<td><%= link_to 'Destroy', pin, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
30 changes: 15 additions & 15 deletions app/views/pins/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<h1>Listing pins</h1>

<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>

<tbody>
<%= render @pins %>
</tbody>
</table>
<tbody>
<%= render @pins %>
</tbody>
</table>

<br />
<br>

<%= link_to 'New Pin', new_pin_path %>
<%= link_to 'New Pin', new_pin_path %>
10 changes: 2 additions & 8 deletions app/views/pins/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
<div class="row">
<div class="span6 offset3">
<%# This puts the grey box around content below %>
<div class="well">
<p>
<%= @pin.description %>
</p>
<p>
<%= @pin.user.name %>
</p>
<% if current_user == @pin.user %>
<%= link_to 'Edit', edit_pin_path(@pin) %> |
<% end %>
<%= link_to 'Back', pins_path %>
<%= link_to 'Edit', edit_pin_path(@pin) %> |
<%= link_to 'Back', pins_path %>
</div>
</div>
</div>
Loading

0 comments on commit e8edabf

Please sign in to comment.