Its better to use new_orders_path then /orders/new
When things become more complicated, do you feel the order_controller.rb is a little bit messy? It is doing a lot of stuffs. Good practices are to use PORO you can check it out here. Or you can try to put some code like calculate_discount_price to the model layer
# In controller do this
@sections = ["Breakfast", "Lunch", "Dinner", "Drinks"]
# And in views you can do:
<div class="btn-group" role="group" aria-label="section">
<% @sections.each do |section| %>
<%= link_to section, menus_path(section: section), class: "btn btn-secondary #{'active' if @section == section}" %>
<% end %>
</div>
or even better way:
# Create a partial view name it: sections/_section.html.erb
<%= link_to section, menus_path(section: section), class: "btn btn-secondary #{'active' if selected_section == section}" %>
# In controller do this
@sections = ["Breakfast", "Lunch", "Dinner", "Drinks"]
# And in views you can do:
<div class="btn-group" role="group" aria-label="section">
<%= render partial: 'sections/section', collection: @sections, as: :section, locals: {selected_section: @section}
</div>
actually there are a better way then this (which I think the best way for me), but we can talk about it later, its more advance and architecture matter
You have done most part of the homework, really appreciate your work
Goals of this homework:
Great stuffs:
raty.js
libraryhas_many
andbelongs_to
relationship, you look confident to use these methodsvalidation
on modelsorder
andwhere
, really awesome stuffssession
fluently, great job manVery nice way of rendering, you know a lot of stuffs man
Suggestions:
new_orders_path
then/orders/new
order_controller.rb
is a little bit messy? It is doing a lot of stuffs. Good practices are to use PORO you can check it out here. Or you can try to put some code likecalculate_discount_price
to the model layerThis code:
can be refactor something like:
or even better way:
actually there are a better way then this (which I think the best way for me), but we can talk about it later, its more advance and architecture matter
This code:
can be refactored into something shorter
or something even shorter
these approaches produce cleaner and more readable code, because someone may have to maintain your code
Overall, you really push effort to do the homework. A lot of nice stuffs have been done. I love your submission most. Please keep it up