Skip to content

Commit

Permalink
bin/rails g scaffold stuff title:string expires_at:datetime unlisted:…
Browse files Browse the repository at this point in the history
…boolean filename:string encrypted_password:string --no-view-specs
  • Loading branch information
sorah committed May 24, 2014
1 parent 84274bb commit 23a7a6e
Show file tree
Hide file tree
Showing 15 changed files with 283 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/stuffs.js.coffee
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/
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;
}
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/stuffs.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the stuffs controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
74 changes: 74 additions & 0 deletions app/controllers/stuffs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class StuffsController < ApplicationController
before_action :set_stuff, only: [:show, :edit, :update, :destroy]

# GET /stuffs
# GET /stuffs.json
def index
@stuffs = Stuff.all
end

# GET /stuffs/1
# GET /stuffs/1.json
def show
end

# GET /stuffs/new
def new
@stuff = Stuff.new
end

# GET /stuffs/1/edit
def edit
end

# POST /stuffs
# POST /stuffs.json
def create
@stuff = Stuff.new(stuff_params)

respond_to do |format|
if @stuff.save
format.html { redirect_to @stuff, notice: 'Stuff was successfully created.' }
format.json { render :show, status: :created, location: @stuff }
else
format.html { render :new }
format.json { render json: @stuff.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /stuffs/1
# PATCH/PUT /stuffs/1.json
def update
respond_to do |format|
if @stuff.update(stuff_params)
format.html { redirect_to @stuff, notice: 'Stuff was successfully updated.' }
format.json { render :show, status: :ok, location: @stuff }
else
format.html { render :edit }
format.json { render json: @stuff.errors, status: :unprocessable_entity }
end
end
end

# DELETE /stuffs/1
# DELETE /stuffs/1.json
def destroy
@stuff.destroy
respond_to do |format|
format.html { redirect_to stuffs_url, notice: 'Stuff was successfully destroyed.' }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_stuff
@stuff = Stuff.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def stuff_params
params.require(:stuff).permit(:title, :expires_at, :unlisted, :filename, :encrypted_password)
end
end
2 changes: 2 additions & 0 deletions app/helpers/stuffs_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module StuffsHelper
end
2 changes: 2 additions & 0 deletions app/models/stuff.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Stuff < ActiveRecord::Base
end
37 changes: 37 additions & 0 deletions app/views/stuffs/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<%= form_for(@stuff) do |f| %>
<% if @stuff.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@stuff.errors.count, "error") %> prohibited this stuff from being saved:</h2>

<ul>
<% @stuff.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :expires_at %><br>
<%= f.datetime_select :expires_at %>
</div>
<div class="field">
<%= f.label :unlisted %><br>
<%= f.check_box :unlisted %>
</div>
<div class="field">
<%= f.label :filename %><br>
<%= f.text_field :filename %>
</div>
<div class="field">
<%= f.label :encrypted_password %><br>
<%= f.text_field :encrypted_password %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/stuffs/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing stuff</h1>

<%= render 'form' %>

<%= link_to 'Show', @stuff %> |
<%= link_to 'Back', stuffs_path %>
33 changes: 33 additions & 0 deletions app/views/stuffs/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<h1>Listing stuffs</h1>

<table>
<thead>
<tr>
<th>Title</th>
<th>Expires at</th>
<th>Unlisted</th>
<th>Filename</th>
<th>Encrypted password</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @stuffs.each do |stuff| %>
<tr>
<td><%= stuff.title %></td>
<td><%= stuff.expires_at %></td>
<td><%= stuff.unlisted %></td>
<td><%= stuff.filename %></td>
<td><%= stuff.encrypted_password %></td>
<td><%= link_to 'Show', stuff %></td>
<td><%= link_to 'Edit', edit_stuff_path(stuff) %></td>
<td><%= link_to 'Destroy', stuff, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Stuff', new_stuff_path %>
4 changes: 4 additions & 0 deletions app/views/stuffs/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
json.array!(@stuffs) do |stuff|
json.extract! stuff, :id, :title, :expires_at, :unlisted, :filename, :encrypted_password
json.url stuff_url(stuff, format: :json)
end
5 changes: 5 additions & 0 deletions app/views/stuffs/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New stuff</h1>

<%= render 'form' %>

<%= link_to 'Back', stuffs_path %>
29 changes: 29 additions & 0 deletions app/views/stuffs/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<p id="notice"><%= notice %></p>

<p>
<strong>Title:</strong>
<%= @stuff.title %>
</p>

<p>
<strong>Expires at:</strong>
<%= @stuff.expires_at %>
</p>

<p>
<strong>Unlisted:</strong>
<%= @stuff.unlisted %>
</p>

<p>
<strong>Filename:</strong>
<%= @stuff.filename %>
</p>

<p>
<strong>Encrypted password:</strong>
<%= @stuff.encrypted_password %>
</p>

<%= link_to 'Edit', edit_stuff_path(@stuff) %> |
<%= link_to 'Back', stuffs_path %>
1 change: 1 addition & 0 deletions app/views/stuffs/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.extract! @stuff, :id, :title, :expires_at, :unlisted, :filename, :encrypted_password, :created_at, :updated_at
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Rails.application.routes.draw do
resources :stuffs

# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20140524061037_create_stuffs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateStuffs < ActiveRecord::Migration
def change
create_table :stuffs do |t|
t.string :title
t.datetime :expires_at
t.boolean :unlisted
t.string :filename
t.string :encrypted_password

t.timestamps
end
end
end

0 comments on commit 23a7a6e

Please sign in to comment.