-
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
Rozwiązanie #268
base: master
Are you sure you want to change the base?
Rozwiązanie #268
Conversation
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.
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| |
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.
brakuje pola name
😢
@@ -0,0 +1,5 @@ | |||
module CustomersHelper | |||
def customers_not_empty? | |||
@customers && !@customers.empty? |
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.
zamiast !@customers.empty?
można napisać @customers.any?
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.
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? |
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.
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) |
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.
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?
zad6/app/helpers/products_helper.rb
Outdated
|
||
def read_categories product | ||
result = []; | ||
product.category_ids.each {|category_id| result << read_category(category_id)} |
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.
Przy odpowiednio napisanych asocjacjach(a są 👍 ) wystarczy:
product.categories.pluck(:name).join(', ')
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.
Racja nie przemyślałem tego dobrze :/
zad6/app/helpers/products_helper.rb
Outdated
end | ||
|
||
def read_customer product | ||
Customer.find(product.customer_id) if has_customer? |
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.
Tak samo tutaj, asocjacje ułatwiają sprawę i można napisać po prostu product.customer
No description provided.