First commit
This commit is contained in:
3
example/app/assets/config/manifest.js
Normal file
3
example/app/assets/config/manifest.js
Normal file
@ -0,0 +1,3 @@
|
||||
//= link_tree ../images
|
||||
//= link_directory ../javascripts .js
|
||||
//= link_directory ../stylesheets .css
|
0
example/app/assets/images/.keep
Normal file
0
example/app/assets/images/.keep
Normal file
16
example/app/assets/javascripts/application.js
Normal file
16
example/app/assets/javascripts/application.js
Normal file
@ -0,0 +1,16 @@
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
|
||||
// vendor/assets/javascripts directory can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
||||
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
||||
//
|
||||
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
||||
// about supported directives.
|
||||
//
|
||||
//= require rails-ujs
|
||||
//= require activestorage
|
||||
//= require turbolinks
|
||||
//= require_tree .
|
13
example/app/assets/javascripts/cable.js
Normal file
13
example/app/assets/javascripts/cable.js
Normal file
@ -0,0 +1,13 @@
|
||||
// Action Cable provides the framework to deal with WebSockets in Rails.
|
||||
// You can generate new channels where WebSocket features live using the `rails generate channel` command.
|
||||
//
|
||||
//= require action_cable
|
||||
//= require_self
|
||||
//= require_tree ./channels
|
||||
|
||||
(function() {
|
||||
this.App || (this.App = {});
|
||||
|
||||
App.cable = ActionCable.createConsumer();
|
||||
|
||||
}).call(this);
|
0
example/app/assets/javascripts/channels/.keep
Normal file
0
example/app/assets/javascripts/channels/.keep
Normal file
3
example/app/assets/javascripts/products.coffee
Normal file
3
example/app/assets/javascripts/products.coffee
Normal file
@ -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/
|
15
example/app/assets/stylesheets/application.css
Normal file
15
example/app/assets/stylesheets/application.css
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
||||
* listed below.
|
||||
*
|
||||
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
|
||||
* vendor/assets/stylesheets directory can be referenced here using a relative path.
|
||||
*
|
||||
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
||||
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
||||
* files in this directory. Styles in this file should be added after the last require_* statement.
|
||||
* It is generally better to create a new file per style scope.
|
||||
*
|
||||
*= require_tree .
|
||||
*= require_self
|
||||
*/
|
3
example/app/assets/stylesheets/products.scss
Normal file
3
example/app/assets/stylesheets/products.scss
Normal file
@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the products controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
84
example/app/assets/stylesheets/scaffolds.scss
Normal file
84
example/app/assets/stylesheets/scaffolds.scss
Normal file
@ -0,0 +1,84 @@
|
||||
body {
|
||||
background-color: #fff;
|
||||
color: #333;
|
||||
margin: 33px;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
th {
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 0 5px 7px;
|
||||
}
|
||||
|
||||
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 7px 0;
|
||||
margin-bottom: 20px;
|
||||
background-color: #f0f0f0;
|
||||
|
||||
h2 {
|
||||
text-align: left;
|
||||
font-weight: bold;
|
||||
padding: 5px 5px 5px 15px;
|
||||
font-size: 12px;
|
||||
margin: -7px -7px 0;
|
||||
background-color: #c00;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
ul li {
|
||||
font-size: 12px;
|
||||
list-style: square;
|
||||
}
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
}
|
4
example/app/channels/application_cable/channel.rb
Normal file
4
example/app/channels/application_cable/channel.rb
Normal file
@ -0,0 +1,4 @@
|
||||
module ApplicationCable
|
||||
class Channel < ActionCable::Channel::Base
|
||||
end
|
||||
end
|
4
example/app/channels/application_cable/connection.rb
Normal file
4
example/app/channels/application_cable/connection.rb
Normal file
@ -0,0 +1,4 @@
|
||||
module ApplicationCable
|
||||
class Connection < ActionCable::Connection::Base
|
||||
end
|
||||
end
|
3
example/app/controllers/application_controller.rb
Normal file
3
example/app/controllers/application_controller.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
before_action :authenticate_user!
|
||||
end
|
0
example/app/controllers/concerns/.keep
Normal file
0
example/app/controllers/concerns/.keep
Normal file
74
example/app/controllers/products_controller.rb
Normal file
74
example/app/controllers/products_controller.rb
Normal file
@ -0,0 +1,74 @@
|
||||
class ProductsController < ApplicationController
|
||||
before_action :set_product, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /products
|
||||
# GET /products.json
|
||||
def index
|
||||
@products = Product.all
|
||||
end
|
||||
|
||||
# GET /products/1
|
||||
# GET /products/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /products/new
|
||||
def new
|
||||
@product = Product.new
|
||||
end
|
||||
|
||||
# GET /products/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /products
|
||||
# POST /products.json
|
||||
def create
|
||||
@product = Product.new(product_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @product.save
|
||||
format.html { redirect_to @product, notice: 'Product was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @product }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @product.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /products/1
|
||||
# PATCH/PUT /products/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @product.update(product_params)
|
||||
format.html { redirect_to @product, notice: 'Product was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @product }
|
||||
else
|
||||
format.html { render :edit }
|
||||
format.json { render json: @product.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /products/1
|
||||
# DELETE /products/1.json
|
||||
def destroy
|
||||
@product.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_product
|
||||
@product = Product.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def product_params
|
||||
params.require(:product).permit(:name, :description, :price)
|
||||
end
|
||||
end
|
2
example/app/helpers/application_helper.rb
Normal file
2
example/app/helpers/application_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module ApplicationHelper
|
||||
end
|
2
example/app/helpers/products_helper.rb
Normal file
2
example/app/helpers/products_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module ProductsHelper
|
||||
end
|
2
example/app/jobs/application_job.rb
Normal file
2
example/app/jobs/application_job.rb
Normal file
@ -0,0 +1,2 @@
|
||||
class ApplicationJob < ActiveJob::Base
|
||||
end
|
4
example/app/mailers/application_mailer.rb
Normal file
4
example/app/mailers/application_mailer.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class ApplicationMailer < ActionMailer::Base
|
||||
default from: 'from@example.com'
|
||||
layout 'mailer'
|
||||
end
|
3
example/app/models/application_record.rb
Normal file
3
example/app/models/application_record.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
end
|
0
example/app/models/concerns/.keep
Normal file
0
example/app/models/concerns/.keep
Normal file
8
example/app/models/customer.rb
Normal file
8
example/app/models/customer.rb
Normal file
@ -0,0 +1,8 @@
|
||||
class Customer < ApplicationRecord
|
||||
# Include default devise modules. Others available are:
|
||||
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :validatable
|
||||
|
||||
has_many :products, through: :purchases
|
||||
end
|
3
example/app/models/product.rb
Normal file
3
example/app/models/product.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class Product < ApplicationRecord
|
||||
has_many :customers, through: :purchases
|
||||
end
|
4
example/app/models/purchase.rb
Normal file
4
example/app/models/purchase.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class Purchase < ApplicationRecord
|
||||
validates :sale_type, :inclusion => { :in => %w{rented bought} }
|
||||
validates :quantity, numericality: { greater_than: 0 }
|
||||
end
|
8
example/app/models/user.rb
Normal file
8
example/app/models/user.rb
Normal file
@ -0,0 +1,8 @@
|
||||
class User < ApplicationRecord
|
||||
# Include default devise modules. Others available are:
|
||||
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :validatable
|
||||
|
||||
has_many :products
|
||||
end
|
15
example/app/views/layouts/application.html.erb
Normal file
15
example/app/views/layouts/application.html.erb
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>App</title>
|
||||
<%= csrf_meta_tags %>
|
||||
<%= csp_meta_tag %>
|
||||
|
||||
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
|
||||
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<%= yield %>
|
||||
</body>
|
||||
</html>
|
13
example/app/views/layouts/mailer.html.erb
Normal file
13
example/app/views/layouts/mailer.html.erb
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<style>
|
||||
/* Email styles need to be inline */
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<%= yield %>
|
||||
</body>
|
||||
</html>
|
1
example/app/views/layouts/mailer.text.erb
Normal file
1
example/app/views/layouts/mailer.text.erb
Normal file
@ -0,0 +1 @@
|
||||
<%= yield %>
|
32
example/app/views/products/_form.html.erb
Normal file
32
example/app/views/products/_form.html.erb
Normal file
@ -0,0 +1,32 @@
|
||||
<%= form_with(model: product, local: true) do |form| %>
|
||||
<% if product.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(product.errors.count, "error") %> prohibited this product from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% product.errors.full_messages.each do |message| %>
|
||||
<li><%= message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :name %>
|
||||
<%= form.text_field :name %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :description %>
|
||||
<%= form.text_area :description %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :price %>
|
||||
<%= form.text_field :price %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= form.submit %>
|
||||
</div>
|
||||
<% end %>
|
2
example/app/views/products/_product.json.jbuilder
Normal file
2
example/app/views/products/_product.json.jbuilder
Normal file
@ -0,0 +1,2 @@
|
||||
json.extract! product, :id, :name, :description, :price, :created_at, :updated_at
|
||||
json.url product_url(product, format: :json)
|
6
example/app/views/products/edit.html.erb
Normal file
6
example/app/views/products/edit.html.erb
Normal file
@ -0,0 +1,6 @@
|
||||
<h1>Editing Product</h1>
|
||||
|
||||
<%= render 'form', product: @product %>
|
||||
|
||||
<%= link_to 'Show', @product %> |
|
||||
<%= link_to 'Back', products_path %>
|
31
example/app/views/products/index.html.erb
Normal file
31
example/app/views/products/index.html.erb
Normal file
@ -0,0 +1,31 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<h1>Products</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Price</th>
|
||||
<th colspan="3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @products.each do |product| %>
|
||||
<tr>
|
||||
<td><%= product.name %></td>
|
||||
<td><%= product.description %></td>
|
||||
<td><%= product.price %></td>
|
||||
<td><%= link_to 'Show', product %></td>
|
||||
<td><%= link_to 'Edit', edit_product_path(product) %></td>
|
||||
<td><%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
<%= link_to 'New Product', new_product_path %>
|
1
example/app/views/products/index.json.jbuilder
Normal file
1
example/app/views/products/index.json.jbuilder
Normal file
@ -0,0 +1 @@
|
||||
json.array! @products, partial: 'products/product', as: :product
|
5
example/app/views/products/new.html.erb
Normal file
5
example/app/views/products/new.html.erb
Normal file
@ -0,0 +1,5 @@
|
||||
<h1>New Product</h1>
|
||||
|
||||
<%= render 'form', product: @product %>
|
||||
|
||||
<%= link_to 'Back', products_path %>
|
19
example/app/views/products/show.html.erb
Normal file
19
example/app/views/products/show.html.erb
Normal file
@ -0,0 +1,19 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<strong>Name:</strong>
|
||||
<%= @product.name %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Description:</strong>
|
||||
<%= @product.description %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Price:</strong>
|
||||
<%= @product.price %>
|
||||
</p>
|
||||
|
||||
<%= link_to 'Edit', edit_product_path(@product) %> |
|
||||
<%= link_to 'Back', products_path %>
|
1
example/app/views/products/show.json.jbuilder
Normal file
1
example/app/views/products/show.json.jbuilder
Normal file
@ -0,0 +1 @@
|
||||
json.partial! "products/product", product: @product
|
Reference in New Issue
Block a user