-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zad6 #262
Open
awaszczuk
wants to merge
1
commit into
DaftAcademy:master
Choose a base branch
from
awaszczuk:zad6
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
zad6 #262
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,7 +185,7 @@ DEPENDENCIES | |
web-console (>= 3.3.0) | ||
|
||
RUBY VERSION | ||
ruby 2.5.3p105 | ||
ruby 2.5.1p57 | ||
|
||
BUNDLED WITH | ||
1.17.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class CustomersController < ApplicationController | ||
|
||
def index | ||
@customers = Customer.all | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do wcięć w rubym używamy 2 spacji 😉 |
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class ProductsController < ApplicationController | ||
|
||
def index | ||
@customer = Customer.find(params[:customer_id]) | ||
@products = @customer.products.order(price: :desc).includes(:categories) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. O, jest nawet preloading |
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Category < ApplicationRecord | ||
has_many :category_products | ||
has_many :products, through: :category_products | ||
validates :name, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class CategoryProduct < ApplicationRecord | ||
belongs_to :product | ||
belongs_to :category | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Customer < ApplicationRecord | ||
has_many :products | ||
validates :name, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Product < ApplicationRecord | ||
belongs_to :customer, optional: true | ||
has_many :category_products | ||
has_many :categories, through: :category_products | ||
validates :name, presence: true | ||
validates :price, presence: true, numericality: {greater_than: 0} #format: { with: /^\d+??(?:\.\d{0,2})?$/ } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<h1>All customers</h1> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Products</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @customers.each do |customer| %> | ||
<tr> | ||
<td><%= customer.name %></td> | ||
<td><%= link_to 'Show all', customer_products_path(customer) %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= link_to 'Customers', customers_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<h1>All products owned by <%= @customer.name %> </h1> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Price</th> | ||
<th>Category</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @products.each do |product| %> | ||
<tr> | ||
<td><%= product.name %></td> | ||
<td><%= product.price %></td> | ||
<td> | ||
<% product.categories.each do |category| %> | ||
<%= category.name %> | ||
<% end %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
Rails.application.routes.draw do | ||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | ||
resources :customers, only: %i[index] do | ||
resources :products, only: %i[index] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class CreateCustomers < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :customers do |t| | ||
t.string :name, null: false | ||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateProducts < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :products do |t| | ||
t.string :name, null: false | ||
t.float :price, null: false | ||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class CreateCategories < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :categories do |t| | ||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddNameToCategory < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :categories, :name, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddCustomerToProduct < ActiveRecord::Migration[5.2] | ||
def change | ||
add_reference :products, :customer | ||
add_reference :products, :categories | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
zad6/db/migrate/20181209165041_create_category_products.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateCategoryProducts < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :category_products do |t| | ||
|
||
t.references :product | ||
t.references :category | ||
|
||
t.timestamps | ||
end | ||
|
||
remove_reference :products, :categories | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# Note that this schema.rb definition is the authoritative source for your | ||
# database schema. If you need to create the application database on another | ||
# system, you should be using db:schema:load, not running all the migrations | ||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
# you'll amass, the slower it'll run and the greater likelihood for issues). | ||
# | ||
# It's strongly recommended that you check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(version: 2018_12_09_165041) do | ||
|
||
create_table "categories", force: :cascade do |t| | ||
t.datetime "created_at", null: false | ||
t.datetime "updated_at", null: false | ||
t.string "name" | ||
end | ||
|
||
create_table "category_products", force: :cascade do |t| | ||
t.integer "product_id" | ||
t.integer "category_id" | ||
t.datetime "created_at", null: false | ||
t.datetime "updated_at", null: false | ||
t.index ["category_id"], name: "index_category_products_on_category_id" | ||
t.index ["product_id"], name: "index_category_products_on_product_id" | ||
end | ||
|
||
create_table "customers", force: :cascade do |t| | ||
t.string "name", null: false | ||
t.datetime "created_at", null: false | ||
t.datetime "updated_at", null: false | ||
end | ||
|
||
create_table "products", force: :cascade do |t| | ||
t.string "name", null: false | ||
t.float "price", null: false | ||
t.datetime "created_at", null: false | ||
t.datetime "updated_at", null: false | ||
t.integer "customer_id" | ||
t.index ["customer_id"], name: "index_products_on_customer_id" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ruby 2.5.3
był jak najbardziej ok, nie trzeba było zmieniać wersji 😉 Żeby zainstalować brakującą wersję wystarczy puścićrvm install 2.5.3
(zakładając, że używamyrvm
, ale z tego co to było narzędzie pokazywane na wykładzie).