Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app/assets
3 changes: 3 additions & 0 deletions app/assets/stylesheets/rentals.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Rentals controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
31 changes: 31 additions & 0 deletions app/controllers/rentals_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class RentalsController < ApplicationController
def index
@rentals = Rental.all
end

def show
@rental = Rental.find_by id: params[:id]
end

def new
@rental = Rental.new
end

def create

em = Rental.new(rental_params)
if em.save
redirect_to rentals_path
else
render :new
end
end
private
def set_rental
@rental = Rental.find_by id:params[:id]
end
def rental_params
params.require(:rental).permit :name, :size , :price, :color, :amount
end

end
2 changes: 2 additions & 0 deletions app/helpers/rentals_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module RentalsHelper
end
2 changes: 2 additions & 0 deletions app/models/rental.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Rental < ApplicationRecord
end
37 changes: 37 additions & 0 deletions app/views/rentals/index.html.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<table>
<thead>
<tr>
<th>Name</th>
<th>Size</th>
<th>Price</th>
<th>Color</th>
<th>Amount</th>
<th>Action</th>
</tr>
</thead>
<%= link_to "new ", new_rental_path %>
<tbody>
<% @rentals.each do |rental| %>
<tr>
<td>
<%= rental.name %>
</td>
<td>
<%= rental.size %>
</td>
<td>
<%= rental.price %>
</td>
<td>
<%= rental.color %>
</td>
<td>
<%= rental.amount %>
</td>
<td>
<%= link_to "show ", rental_path(rental.id) %>
</td>
</tr>
<% end %>
</tbody>
</table>
19 changes: 19 additions & 0 deletions app/views/rentals/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<%= form_for(@rental) do |f| %>
Name:
<Br>
<%= f.text_field :name %>
Size:
<Br>
<%= f.text_field :size %>
Price:
<br>
<%= f.text_field :price %>
Color:
<br>
<%= f.text_field :color %>
Amount:
<br>
<%= f.text_field :amount %>
<br>
<%= f.submit "Create" %>
<% end %>
19 changes: 19 additions & 0 deletions app/views/rentals/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<p id="notice">
<%= notice %>
</p>
<p><strong>Name: </strong>
<%= @rental.name %>
<p>
<p><strong>Size: </strong>
<%= @rental.size %>
<p>
<p><strong>Price: </strong>
<%= @rental.price %>
<p>
<p><strong>Color: </strong>
<%= @rental.color %>
<p>
<p><strong>Amount: </strong>
<%= @rental.amount %>
</p>
<%= link_to 'Back', rentals_path %>
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
Rails.application.routes.draw do
get 'rentals/new'
get 'rentals/edit'
get 'rentals/show'
get 'rentals/index'

get 'employees/new'
get 'employees/edit'
get 'employees/update'
Expand All @@ -21,6 +26,7 @@
get 'static_page/logout'

resources :employees
resources :rentals

# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
4 changes: 0 additions & 4 deletions db/migrate/20180311141522_remve_password_from_employee.rb

This file was deleted.

13 changes: 13 additions & 0 deletions db/migrate/20180313105827_create_rentals.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateRentals < ActiveRecord::Migration[5.1]
def change
create_table :rentals do |t|
t.string :name
t.string :size
t.double :price
t.string :color
t.double :amount

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

ActiveRecord::Schema.define(version: 20180311141915) do
ActiveRecord::Schema.define(version: 20180313092033) do

create_table "employees", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "name"
Expand All @@ -21,6 +21,16 @@
t.string "password_confirm"
end

create_table "rentals", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "name"
t.string "size"
t.double "price"
t.string "color"
t.double "amount"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "Name"
t.string "Email"
Expand Down
Loading