-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Blair Anderson
committed
Mar 10, 2015
1 parent
788b8ee
commit 5fb5058
Showing
7 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
class Admin::ItemsController < ApplicationController | ||
before_action :set_admin_item, only: [:show, :edit, :update, :destroy] | ||
|
||
# GET /admin/items | ||
# GET /admin/items.json | ||
def index | ||
@admin_items = Admin::Item.all | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.json { render json: @admin_items } | ||
end | ||
end | ||
|
||
# GET /admin/items/1 | ||
# GET /admin/items/1.json | ||
def show | ||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.json { render json: @admin_item } | ||
end | ||
end | ||
|
||
# GET /admin/items/new | ||
def new | ||
@admin_item = Admin::Item.new | ||
end | ||
|
||
# GET /admin/items/1/edit | ||
def edit | ||
end | ||
|
||
# POST /admin/items | ||
# POST /admin/items.json | ||
def create | ||
@admin_item = Admin::Item.new(admin_item_params) | ||
|
||
respond_to do |format| | ||
if @admin_item.save | ||
format.html { redirect_to @admin_item, notice: 'Item was successfully created.' } | ||
format.json { render json: @admin_item, status: :created } | ||
else | ||
format.html { render action: 'new' } | ||
format.json { render json: @admin_item.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /admin/items/1 | ||
# PATCH/PUT /admin/items/1.json | ||
def update | ||
respond_to do |format| | ||
if @admin_item.update(admin_item_params) | ||
format.html { redirect_to @admin_item, notice: 'Item was successfully updated.' } | ||
format.json { head :no_content } | ||
else | ||
format.html { render action: 'edit' } | ||
format.json { render json: @admin_item.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /admin/items/1 | ||
# DELETE /admin/items/1.json | ||
def destroy | ||
@admin_item.destroy | ||
respond_to do |format| | ||
format.html { redirect_to admin_items_url } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_admin_item | ||
@admin_item = Admin::Item.find(params[:id]) | ||
end | ||
|
||
# Never trust parameters from the scary internet, only allow the white list through. | ||
def admin_item_params | ||
params[:admin_item] | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<%= simple_form_for(@admin_item) do |f| %> | ||
<%= f.error_notification %> | ||
|
||
<div class="form-inputs"> | ||
</div> | ||
|
||
<div class="form-actions"> | ||
<%= f.button :submit %> | ||
</div> | ||
<% end %> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing Admin Item</h1> | ||
|
||
<%= render 'form' %> | ||
|
||
<%= link_to 'Show', @admin_item %> | | ||
<%= link_to 'Back', admin_items_path %> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<h1>Listing Admin Items</h1> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th colspan="3"></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @admin_items.each do |admin_item| %> | ||
<tr> | ||
<td><%= link_to 'Show', admin_item %></td> | ||
<td><%= link_to 'Edit', edit_admin_item_path(admin_item) %></td> | ||
<td><%= link_to 'Destroy', admin_item, method: :delete, data: { confirm: 'Are you sure?' } %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
<br> | ||
|
||
<%= link_to 'New Item', new_admin_item_path %> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>New Admin Item</h1> | ||
|
||
<%= render 'form' %> | ||
|
||
<%= link_to 'Back', admin_items_path %> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<%= link_to 'Edit', edit_admin_item_path(@admin_item) %> | | ||
<%= link_to 'Back', admin_items_path %> |
This file contains 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