Skip to content

Commit 0b78400

Browse files
committed
wip Add insert Lunchbox
1 parent 12f1cfd commit 0b78400

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

app/controllers/admin/lunchboxes_controller.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def create
2424
@lunchbox = Lunchbox.new(lunchbox_params)
2525

2626
if @lunchbox.save
27-
redirect_to @lunchbox, notice: 'Lunchbox was successfully created.'
27+
redirect_to admin_lunchboxes_path, notice: 'Lunchbox was successfully created.'
2828
else
2929
render :new
3030
end
@@ -51,8 +51,13 @@ def set_lunchbox
5151
@lunchbox = Lunchbox.find(params[:id])
5252
end
5353

54-
# Only allow a trusted parameter "white list" through.
54+
# # Only allow a trusted parameter "white list" through.
55+
# def lunchbox_params
56+
# params.fetch(:lunchbox, {})
57+
# end
58+
5559
def lunchbox_params
56-
params.fetch(:lunchbox, {})
60+
params.require(:lunchbox).permit(:name, :price)
5761
end
62+
5863
end
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
h1 New lunchbox
22

3-
== render 'form'
3+
= form_for(@lunchbox, url: admin_lunchboxes_path) do |f|
4+
- if @lunchbox.errors.any?
5+
#error_explanation
6+
h2 = "#{pluralize(@lunchbox.errors.count, "error")} prohibited this lunchbox from being saved:"
7+
ul
8+
- @lunchbox.errors.full_messages.each do |message|
9+
li = message
410

5-
= link_to 'Back', lunchboxes_path
11+
fieldset
12+
.form-group
13+
= f.label :name
14+
= f.text_field :name, class: 'form-control'
15+
16+
.form-group
17+
= f.label :price
18+
= f.text_field :price, class: 'form-control'
19+
20+
.actions = f.submit
21+
22+
/= link_to 'Back', lunchboxes_path

0 commit comments

Comments
 (0)