Skip to content

Commit 12f1cfd

Browse files
committed
wip Add index action for lunchbox in admin
1 parent 88c5360 commit 12f1cfd

File tree

15 files changed

+267
-0
lines changed

15 files changed

+267
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Place all the behaviors and hooks related to the matching controller here.
2+
// All this logic will automatically be available in application.js.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place all the styles related to the admin/lunchbox controller here.
2+
// They will automatically be included in application.css.
3+
// You can use Sass (SCSS) here: http://sass-lang.com/
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
body {
2+
background-color: #fff;
3+
color: #333;
4+
font-family: verdana, arial, helvetica, sans-serif;
5+
font-size: 13px;
6+
line-height: 18px;
7+
margin: 33px;
8+
}
9+
10+
p, ol, ul, td {
11+
font-family: verdana, arial, helvetica, sans-serif;
12+
font-size: 13px;
13+
line-height: 18px;
14+
margin: 33px;
15+
}
16+
17+
pre {
18+
background-color: #eee;
19+
padding: 10px;
20+
font-size: 11px;
21+
}
22+
23+
a {
24+
color: #000;
25+
26+
&:visited {
27+
color: #666;
28+
}
29+
30+
&:hover {
31+
color: #fff;
32+
background-color: #000;
33+
}
34+
}
35+
36+
th {
37+
padding-bottom: 5px;
38+
}
39+
40+
td {
41+
padding-bottom: 7px;
42+
padding-left: 5px;
43+
padding-right: 5px;
44+
}
45+
46+
div {
47+
&.field, &.actions {
48+
margin-bottom: 10px;
49+
}
50+
}
51+
52+
#notice {
53+
color: green;
54+
}
55+
56+
.field_with_errors {
57+
padding: 2px;
58+
background-color: red;
59+
display: table;
60+
}
61+
62+
#error_explanation {
63+
width: 450px;
64+
border: 2px solid red;
65+
padding: 7px;
66+
padding-bottom: 0;
67+
margin-bottom: 20px;
68+
background-color: #f0f0f0;
69+
70+
h2 {
71+
text-align: left;
72+
font-weight: bold;
73+
padding: 5px 5px 5px 15px;
74+
font-size: 12px;
75+
margin: -7px;
76+
margin-bottom: 0;
77+
background-color: #c00;
78+
color: #fff;
79+
}
80+
81+
ul li {
82+
font-size: 12px;
83+
list-style: square;
84+
}
85+
}
86+
87+
label {
88+
display: block;
89+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
class Admin::LunchboxesController < ApplicationController
2+
before_action :set_lunchbox, only: [:show, :edit, :update, :destroy]
3+
4+
# GET /lunchboxes
5+
def index
6+
@lunchboxes = Lunchbox.all
7+
end
8+
9+
# GET /lunchboxes/1
10+
def show
11+
end
12+
13+
# GET /lunchboxes/new
14+
def new
15+
@lunchbox = Lunchbox.new
16+
end
17+
18+
# GET /lunchboxes/1/edit
19+
def edit
20+
end
21+
22+
# POST /lunchboxes
23+
def create
24+
@lunchbox = Lunchbox.new(lunchbox_params)
25+
26+
if @lunchbox.save
27+
redirect_to @lunchbox, notice: 'Lunchbox was successfully created.'
28+
else
29+
render :new
30+
end
31+
end
32+
33+
# PATCH/PUT /lunchboxes/1
34+
def update
35+
if @lunchbox.update(lunchbox_params)
36+
redirect_to @lunchbox, notice: 'Lunchbox was successfully updated.'
37+
else
38+
render :edit
39+
end
40+
end
41+
42+
# DELETE /lunchboxes/1
43+
def destroy
44+
@lunchbox.destroy
45+
redirect_to lunchboxes_url, notice: 'Lunchbox was successfully destroyed.'
46+
end
47+
48+
private
49+
# Use callbacks to share common setup or constraints between actions.
50+
def set_lunchbox
51+
@lunchbox = Lunchbox.find(params[:id])
52+
end
53+
54+
# Only allow a trusted parameter "white list" through.
55+
def lunchbox_params
56+
params.fetch(:lunchbox, {})
57+
end
58+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module Admin::LunchboxHelper
2+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module Admin::LunchboxesHelper
2+
end

app/models/admin.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Admin
2+
def self.table_name_prefix
3+
'admin_'
4+
end
5+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
= form_for @lunchbox do |f|
2+
- if @lunchbox.errors.any?
3+
#error_explanation
4+
h2 = "#{pluralize(@lunchbox.errors.count, "error")} prohibited this lunchbox from being saved:"
5+
ul
6+
- @lunchbox.errors.full_messages.each do |message|
7+
li = message
8+
9+
.actions = f.submit
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
h1 Editing lunchbox
2+
3+
== render 'form'
4+
5+
= link_to 'Show', @lunchbox
6+
' |
7+
= link_to 'Back', lunchboxes_path
8+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
h1 Listing lunchboxes
2+
3+
table
4+
thead
5+
tr
6+
th
7+
th
8+
th
9+
th
10+
11+
tbody
12+
- @lunchboxes.each do |lunchbox|
13+
tr
14+
td = lunchbox.name
15+
td = link_to 'Show', admin_lunchbox_path(lunchbox)
16+
td = link_to 'Edit', edit_admin_lunchbox_path(lunchbox)
17+
td = link_to 'Destroy', admin_lunchbox_path(lunchbox), data: { confirm: 'Are you sure?' }, method: :delete
18+
19+
br
20+
21+
= link_to 'New Lunchbox', new_admin_lunchbox_path

0 commit comments

Comments
 (0)