Skip to content

Commit

Permalink
add admin/items routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Blair Anderson committed Mar 10, 2015
1 parent 788b8ee commit 5fb5058
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 0 deletions.
83 changes: 83 additions & 0 deletions app/controllers/admin/items_controller.rb
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
10 changes: 10 additions & 0 deletions app/views/admin/items/_form.html.erb
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 %>
6 changes: 6 additions & 0 deletions app/views/admin/items/edit.html.erb
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 %>
25 changes: 25 additions & 0 deletions app/views/admin/items/index.html.erb
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 %>
5 changes: 5 additions & 0 deletions app/views/admin/items/new.html.erb
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 %>
4 changes: 4 additions & 0 deletions app/views/admin/items/show.html.erb
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 %>
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Rails.application.routes.draw do
namespace :admin do
resources :items
end

root to: 'items#index'
resources :user_sessions, only: [:new, :create, :destroy]
resources :users, except: [:index]
Expand Down

0 comments on commit 5fb5058

Please sign in to comment.