Open minhchau273 opened 8 years ago
spec
folder and not use the test
folder, consider removing it.ruby-version
and .ruby-gemset
with RVM!nav-tabs
for section.col-sm-8
and .col-sm-4
. that way, on mobile screens, they each take the full width.MenuItem
and Section
def image_url_or_default
if image_url.present?
image_url
else
"#{IMAGE_BASE_URL}#{CGI.escape name}"
end
end
Additionally, I know I wrote this code in the walkthrough so that it's readable to new Rubists. As you are more comfortable Ruby, you can write it more idiomatically as
def image_url_or_default
image_url.presence || "#{IMAGE_BASE_URL}#{CGI.escape name}"
end
number_with_precision
helper and it is cool that you know how to include the helper methods to a model. You can also check out number_to_currency
method (although it would take a few arguments to display nicely in VND). In general, avoid having to use helper methods in a model, but your use case is fine.menu#index
action can be simplified to (note how I remove many lines that deal with section)# file: menu_controller.rb
def index
@sections = Section.all
@section = Section.find_by_id(params[:session]) || Section.first
@sort = params[:sort] || "alphabetical"
@menu_items = MenuItem.filter(@section.menu_items, @sort)
end
Note you'd have to define def self.filter
yourself in MenuItem
model.
You can improve it further by:
order("price")
or order("price DESC")
to sort instead of using sort_by
. See the official guide.where
and order
methods together.params[:session_id]
instead of params[:session]
-- use the _id
suffix for param keys that are for model ids.Thanks for giving this homework a try. Look forward to your feedback on ways to make it better as well.
+1. What we really need is a set of guides and/or guides (documents) to help explain certain key concepts useful in this homework.
Amazing job to both of you.
Hi @harley, Could you please review my homework? Sorry I didn't complete all the required feature :disappointed: Thank you!