Skip to content

Commit

Permalink
Add text_sample scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesdeb committed Apr 4, 2020
1 parent ad36d32 commit 889b29c
Show file tree
Hide file tree
Showing 24 changed files with 518 additions and 3 deletions.
65 changes: 65 additions & 0 deletions app/assets/stylesheets/scaffolds.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
body {
background-color: #fff;
color: #333;
margin: 33px; }

body, 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; }

a:visited {
color: #666; }

a:hover {
color: #fff;
background-color: #000; }

th {
padding-bottom: 5px; }

td {
padding: 0 5px 7px; }

div.field,
div.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 7px 0;
margin-bottom: 20px;
background-color: #f0f0f0; }

#error_explanation h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px -7px 0;
background-color: #c00;
color: #fff; }

#error_explanation ul li {
font-size: 12px;
list-style: square; }

label {
display: block; }
3 changes: 3 additions & 0 deletions app/assets/stylesheets/text_samples.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the TextSamples controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
74 changes: 74 additions & 0 deletions app/controllers/text_samples_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class TextSamplesController < ApplicationController
before_action :set_text_sample, only: [:show, :edit, :update, :destroy]

# GET /text_samples
# GET /text_samples.json
def index
@text_samples = TextSample.all
end

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

# GET /text_samples/new
def new
@text_sample = TextSample.new
end

# GET /text_samples/1/edit
def edit
end

# POST /text_samples
# POST /text_samples.json
def create
@text_sample = TextSample.new(text_sample_params)

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

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

# DELETE /text_samples/1
# DELETE /text_samples/1.json
def destroy
@text_sample.destroy
respond_to do |format|
format.html { redirect_to text_samples_url, notice: 'Text sample was successfully destroyed.' }
format.json { head :no_content }
end
end

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

# Only allow a list of trusted parameters through.
def text_sample_params
params.require(:text_sample).permit(:description, :text)
end
end
2 changes: 2 additions & 0 deletions app/helpers/text_samples_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module TextSamplesHelper
end
2 changes: 2 additions & 0 deletions app/models/text_sample.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class TextSample < ApplicationRecord
end
27 changes: 27 additions & 0 deletions app/views/text_samples/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%= form_with(model: text_sample, local: true) do |form| %>
<% if text_sample.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(text_sample.errors.count, "error") %> prohibited this text_sample from being saved:</h2>

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

<div class="field">
<%= form.label :description %>
<%= form.text_field :description %>
</div>

<div class="field">
<%= form.label :text %>
<%= form.text_area :text %>
</div>

<div class="actions">
<%= form.submit %>
</div>
<% end %>
2 changes: 2 additions & 0 deletions app/views/text_samples/_text_sample.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! text_sample, :id, :description, :text, :created_at, :updated_at
json.url text_sample_url(text_sample, format: :json)
6 changes: 6 additions & 0 deletions app/views/text_samples/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing Text Sample</h1>

<%= render 'form', text_sample: @text_sample %>

<%= link_to 'Show', @text_sample %> |
<%= link_to 'Back', text_samples_path %>
29 changes: 29 additions & 0 deletions app/views/text_samples/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<p id="notice"><%= notice %></p>

<h1>Text Samples</h1>

<table>
<thead>
<tr>
<th>Description</th>
<th>Text</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @text_samples.each do |text_sample| %>
<tr>
<td><%= text_sample.description %></td>
<td><%= text_sample.text %></td>
<td><%= link_to 'Show', text_sample %></td>
<td><%= link_to 'Edit', edit_text_sample_path(text_sample) %></td>
<td><%= link_to 'Destroy', text_sample, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Text Sample', new_text_sample_path %>
1 change: 1 addition & 0 deletions app/views/text_samples/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @text_samples, partial: "text_samples/text_sample", as: :text_sample
5 changes: 5 additions & 0 deletions app/views/text_samples/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New Text Sample</h1>

<%= render 'form', text_sample: @text_sample %>

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

<p>
<strong>Description:</strong>
<%= @text_sample.description %>
</p>

<p>
<strong>Text:</strong>
<%= @text_sample.text %>
</p>

<%= link_to 'Edit', edit_text_sample_path(@text_sample) %> |
<%= link_to 'Back', text_samples_path %>
1 change: 1 addition & 0 deletions app/views/text_samples/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "text_samples/text_sample", text_sample: @text_sample
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Rails.application.routes.draw do
get 'welcome/index'
resources :text_samples

root 'welcome#index'
root 'text_samples#index'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
10 changes: 10 additions & 0 deletions db/migrate/20200404204856_create_text_samples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateTextSamples < ActiveRecord::Migration[6.0]
def change
create_table :text_samples do |t|
t.string :description
t.text :text

t.timestamps
end
end
end
9 changes: 8 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 0) do
ActiveRecord::Schema.define(version: 2020_04_04_204856) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "text_samples", force: :cascade do |t|
t.string "description"
t.text "text"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

end
15 changes: 15 additions & 0 deletions spec/helpers/text_samples_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

# Specs in this file have access to a helper object that includes
# the TextSamplesHelper. For example:
#
# describe TextSamplesHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe TextSamplesHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/models/text_sample_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe TextSample, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading

0 comments on commit 889b29c

Please sign in to comment.