1
0
Fork 0

Finish up stattypes

This commit is contained in:
Andrew Tomaka 2015-10-20 19:27:59 -04:00
parent 7a839563f1
commit faa1f56aec
12 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the Admin::StatTypes controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,63 @@
class Admin::StatTypesController < Admin::BaseController
before_action :set_stat_type, only: [:show, :edit, :update, :destroy]
after_action :verify_authorized
def index
@stat_types = StatType.all
authorize StatType
end
def show
authorize @stat_type
end
def new
@stat_type = StatType.new
authorize @stat_type
end
def create
@stat_type = StatType.new(stat_type_params)
authorize @stat_type
if @stat_type.save
redirect_to admin_stat_types_path, notice: 'StatType was created'
else
render :new
end
end
def edit
authorize @stat_type
end
def update
authorize @stat_type
if @stat_type.update(stat_type_params)
redirect_to admin_stat_types_path, notice: 'StatType was updated'
else
render :edit
end
end
def destroy
authorize @stat_type
@stat_type.destroy
redirect_to admin_stat_types_path, notice: 'StatType was deleted'
end
private
def stat_type_params
params.require(:stat_type).permit(:name, :description)
end
def set_stat_type
@stat_type = StatType.find(params[:id])
end
end

View File

@ -0,0 +1,2 @@
module Admin::StatTypesHelper
end

View File

@ -1,2 +1,7 @@
class StatType < ActiveRecord::Base
has_paper_trail
validates :name, presence: true,
uniqueness: { case_sensitive: false }
validates :description, presence: true
end

View File

@ -0,0 +1,17 @@
class StatTypePolicy < ApplicationPolicy
def index?
true
end
def create?
user.admin?
end
def update?
user.admin?
end
def destroy?
user.admin?
end
end

View File

@ -41,6 +41,8 @@
li= link_to 'Awaken Types', admin_awaken_types_path
- if policy(:rarity).index?
li= link_to 'Rarities', admin_rarities_path
- if policy(:stat_type).index?
li= link_to 'Stat Types', admin_stat_types_path
- if policy(:type).index?
li= link_to 'Types', admin_types_path
- if policy(:user).index?

View File

@ -0,0 +1,6 @@
= simple_form_for [:admin, @stat_type] do |f|
.form-inputs
= f.input :name
= f.input :description
.form-actions
= f.button :button

View File

@ -0,0 +1 @@
== render 'form'

View File

@ -0,0 +1,29 @@
- if policy(:stat_type).new?
.row
.col-md-12
.pull-right
= link_to 'New Stat Type', new_admin_stat_type_path, class: 'btn btn-primary'
.row
.col-md-12
table.table.table-striped.table-hover
thead
tr
th Name
th Description
th Actions
tbody
- @stat_types.each do |stat_type|
tr
td= stat_type.name
td= stat_type.description
td
- if policy(:stat_type).edit?
= link_to glyph('edit', classes: 'control-icon'), edit_admin_stat_type_path(stat_type)
- if policy(:stat_type).destroy?
= link_to glyph('trash', classes: 'control-icon'), admin_stat_type_path(stat_type), method: :delete
- if policy(:stat_type).new?
.row
.col-md-12
= link_to 'New Stat Type', new_admin_stat_type_path, class: 'btn btn-primary'

View File

@ -0,0 +1 @@
== render 'form'

View File

@ -22,6 +22,7 @@ Rails.application.routes.draw do
resources :links
resources :passive_skills
resources :rarities
resources :stat_types
resources :super_attacks
resources :types
resources :users, except: [:new, :create]