Skip to content
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

Rozwiązanie #268

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Rozwiązanie #268

wants to merge 10 commits into from

Conversation

pkaput
Copy link

@pkaput pkaput commented Dec 10, 2018

No description provided.

@ahawrylak ahawrylak added the zad6 label Dec 11, 2018
@ahawrylak ahawrylak self-assigned this Dec 11, 2018
Copy link
Collaborator

@ahawrylak ahawrylak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dzięki za przesłanie rozwiązania 🎉 Kilka rzeczy można poprawić, żeby aplikacja zachowywała się zgodnie z treścią zadania 😉

@@ -0,0 +1,9 @@
class CreateCustomers < ActiveRecord::Migration[5.2]
def change
create_table :customers do |t|
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brakuje pola name 😢

@@ -0,0 +1,5 @@
module CustomersHelper
def customers_not_empty?
@customers && !@customers.empty?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zamiast !@customers.empty? można napisać @customers.any?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Właśnie tej metody mi brakowało, dzięki! 👍

@@ -0,0 +1,3 @@
%h1 #{link_to @customer.email, customer_path(@customer)}
- if customers_not_empty?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customers_not_empty? w tym miejscu zawsze zwraca nil przez co produkty nigdy nie są wyświetlane 😢

private

def products_filtered
products.where('price > ?', price)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tę metodę można przenieśc do modelu jako scope. Dodatkowo w zadaniu była mowa o tym żeby wyświetlić produkty TAŃSZE niż podane price 😉 + co się stanie jeśli params[:price] w ogóle nie będzie podane?


def read_categories product
result = [];
product.category_ids.each {|category_id| result << read_category(category_id)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Przy odpowiednio napisanych asocjacjach(a są 👍 ) wystarczy:

product.categories.pluck(:name).join(', ')

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Racja nie przemyślałem tego dobrze :/

end

def read_customer product
Customer.find(product.customer_id) if has_customer?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tak samo tutaj, asocjacje ułatwiają sprawę i można napisać po prostu product.customer

@ahawrylak ahawrylak added the ✓ Done in the summary it is considered as done label Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✓ Done in the summary it is considered as done zad6
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants