Finish up stattypes
This commit is contained in:
parent
7a839563f1
commit
faa1f56aec
12 changed files with 133 additions and 0 deletions
3
app/assets/javascripts/admin/stat_types.coffee
Normal file
3
app/assets/javascripts/admin/stat_types.coffee
Normal 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/
|
3
app/assets/stylesheets/admin/stat_types.scss
Normal file
3
app/assets/stylesheets/admin/stat_types.scss
Normal 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/
|
63
app/controllers/admin/stat_types_controller.rb
Normal file
63
app/controllers/admin/stat_types_controller.rb
Normal 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
|
2
app/helpers/admin/stat_types_helper.rb
Normal file
2
app/helpers/admin/stat_types_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
module Admin::StatTypesHelper
|
||||||
|
end
|
|
@ -1,2 +1,7 @@
|
||||||
class StatType < ActiveRecord::Base
|
class StatType < ActiveRecord::Base
|
||||||
|
has_paper_trail
|
||||||
|
|
||||||
|
validates :name, presence: true,
|
||||||
|
uniqueness: { case_sensitive: false }
|
||||||
|
validates :description, presence: true
|
||||||
end
|
end
|
||||||
|
|
17
app/policies/stat_type_policy.rb
Normal file
17
app/policies/stat_type_policy.rb
Normal 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
|
|
@ -41,6 +41,8 @@
|
||||||
li= link_to 'Awaken Types', admin_awaken_types_path
|
li= link_to 'Awaken Types', admin_awaken_types_path
|
||||||
- if policy(:rarity).index?
|
- if policy(:rarity).index?
|
||||||
li= link_to 'Rarities', admin_rarities_path
|
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?
|
- if policy(:type).index?
|
||||||
li= link_to 'Types', admin_types_path
|
li= link_to 'Types', admin_types_path
|
||||||
- if policy(:user).index?
|
- if policy(:user).index?
|
||||||
|
|
6
app/views/admin/stat_types/_form.html.slim
Normal file
6
app/views/admin/stat_types/_form.html.slim
Normal 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
|
1
app/views/admin/stat_types/edit.html.slim
Normal file
1
app/views/admin/stat_types/edit.html.slim
Normal file
|
@ -0,0 +1 @@
|
||||||
|
== render 'form'
|
29
app/views/admin/stat_types/index.html.slim
Normal file
29
app/views/admin/stat_types/index.html.slim
Normal 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'
|
1
app/views/admin/stat_types/new.html.slim
Normal file
1
app/views/admin/stat_types/new.html.slim
Normal file
|
@ -0,0 +1 @@
|
||||||
|
== render 'form'
|
|
@ -22,6 +22,7 @@ Rails.application.routes.draw do
|
||||||
resources :links
|
resources :links
|
||||||
resources :passive_skills
|
resources :passive_skills
|
||||||
resources :rarities
|
resources :rarities
|
||||||
|
resources :stat_types
|
||||||
resources :super_attacks
|
resources :super_attacks
|
||||||
resources :types
|
resources :types
|
||||||
resources :users, except: [:new, :create]
|
resources :users, except: [:new, :create]
|
||||||
|
|
Loading…
Reference in a new issue