mirror of
https://github.com/fspc/bike-database.git
synced 2026-09-16 08:31:39 -04:00
add scaffold & bike form
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the Bikes controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,62 @@
|
||||
class BikesController < ApplicationController
|
||||
before_action :set_bike, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@bikes = Bike.all
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
@bike = Bike.new
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def create
|
||||
@bike = Bike.new(bike_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @bike.save
|
||||
format.html { redirect_to @bike, notice: 'Bike was successfully created.' }
|
||||
format.json { render action: 'show', status: :created, location: @bike }
|
||||
else
|
||||
format.html { render action: 'new' }
|
||||
format.json { render json: @bike.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @bike.update(bike_params)
|
||||
format.html { redirect_to @bike, notice: 'Bike was successfully updated.' }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: 'edit' }
|
||||
format.json { render json: @bike.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@bike.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to bikes_url }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_bike
|
||||
@bike = Bike.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def bike_params
|
||||
params.require(:bike).permit(:entry_date, :brand, :model, :type, :color, :frame_size, :freecyclery, :sale, :serial_number, :notes, :tag_info, :repaired_by, :completion_date, :price, :created_at, :updated_at)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,2 @@
|
||||
module BikesHelper
|
||||
end
|
||||
@@ -0,0 +1,2 @@
|
||||
class Bike < ActiveRecord::Base
|
||||
end
|
||||
@@ -0,0 +1,51 @@
|
||||
<%= form_for(@bike) do |f| %>
|
||||
<% if @bike.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(@bike.errors.count, "error") %> prohibited this bike from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% @bike.errors.full_messages.each do |msg| %>
|
||||
<li><%= msg %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= f.label "Bike Entry Date:" %>
|
||||
<%= f.text_field :entry_date %>
|
||||
<br>
|
||||
<%= f.label "Brand:" %>
|
||||
<%= f.text_field :brand %>
|
||||
<br>
|
||||
<%= f.label "Type:" %>
|
||||
<%= f.text_field :type %>
|
||||
<br>
|
||||
<%= f.label "Freecyclery?" %>
|
||||
<%= f.check_box :freecyclery %>
|
||||
<br>
|
||||
<%= f.label "Sale?" %>
|
||||
<%= f.check_box :sale %>
|
||||
<br>
|
||||
<%= f.label "Serial Number" %>
|
||||
<%= f.text_field :serial_number %>
|
||||
<br>
|
||||
<%= f.label "Notes" %>
|
||||
<%= f.text_area :notes %>
|
||||
<br>
|
||||
<%= f.label "Tag Info" %>
|
||||
<%= f.text_area :tag_info %>
|
||||
<br>
|
||||
<%= f.label "Repaired by:" %>
|
||||
<%= f.text_field :repaired_by %>
|
||||
<br>
|
||||
<%= f.label "Completion Date:" %>
|
||||
<%= f.text_field :completion_date %>
|
||||
<br>
|
||||
<%= f.label "Price" %>
|
||||
<%= f.text_field :price %>
|
||||
<br>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -0,0 +1,6 @@
|
||||
<h1>Editing bike</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Show', @bike %> |
|
||||
<%= link_to 'Back', bikes_path %>
|
||||
@@ -0,0 +1,25 @@
|
||||
<h1>Listing bikes</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @bikes.each do |bike| %>
|
||||
<tr>
|
||||
<td><%= link_to 'Show', bike %></td>
|
||||
<td><%= link_to 'Edit', edit_bike_path(bike) %></td>
|
||||
<td><%= link_to 'Destroy', bike, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
<%= link_to 'New Bike', new_bike_path %>
|
||||
@@ -0,0 +1,4 @@
|
||||
json.array!(@bikes) do |bike|
|
||||
json.extract! bike,
|
||||
json.url bike_url(bike, format: :json)
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
<h1>New bike</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Back', bikes_path %>
|
||||
@@ -0,0 +1,4 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<%= link_to 'Edit', edit_bike_path(@bike) %> |
|
||||
<%= link_to 'Back', bikes_path %>
|
||||
@@ -0,0 +1 @@
|
||||
json.extract! @bike, :created_at, :updated_at
|
||||
Reference in New Issue
Block a user