Last active
December 16, 2019 03:09
-
-
Save scrabill/d32fb9968c2d7bbbae5df7bd9df4fc72 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # From this... | |
| def create | |
| @order = Order.create(order_params) | |
| if @order.save | |
| redirect_to order_path(@order) | |
| else | |
| render :new | |
| end | |
| end | |
| # To this... | |
| def create | |
| @order = Order.create(order_params) | |
| items_to_add = params[:order][:menu_item_ids] | |
| items_to_add.each do |item_id| | |
| if item_id != "" | |
| item_id = item_id.to_i | |
| item_to_add = MenuItem.find_by_id(item_id) | |
| @order.menu_items << item_to_add | |
| end | |
| end | |
| if @order.save | |
| redirect_to order_path(@order) | |
| else | |
| render :new | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment