class SpeechBalloonTemplatesController < ApplicationController
before_filter :authenticate_user!, :only => [:index, :show]
- before_filter :authenticate_admin!, :only => [:list, :browse, :import, :destroy]
+ before_filter :authenticate_admin!, :only => [:list, :browse, :destroy]
- private
-
- def validate_param(ft)
- res = nil
- bl = ft[:size_count].to_i
- tl = ft[:tail_count].to_i
- if bl * tl == ft[:balloon_templates_attributes].size
- flag = []
- bl.times do |i|
- flag[i] = []
- tl.times do |j|
- flag[i][j] = true
- end
- end
- ft[:balloon_templates_attributes].each do |k, t|
- flag[t[:size].to_i - 1][t[:tail].to_i - 1] = nil
- end
- if flag.flatten.compact.size == 0
- else
- res = "invalid variation"
- end
- else
- res = "invalid template size"
- end
- res
- end
-
- public
# GET /speech_balloon_templates
# GET /speech_balloon_templates.json
def index
- @speech_balloon_templates = SpeechBalloonTemplate.all
+ @speech_balloon_templates = SpeechBalloonTemplate.list
respond_to do |format|
format.html # index.html.erb
# GET /speech_balloon_templates/1
# GET /speech_balloon_templates/1.json
def show
- @speech_balloon_template = SpeechBalloonTemplate.find(params[:id])
+ @speech_balloon_template = SpeechBalloonTemplate.show(params[:id])
respond_to do |format|
format.html # show.html.erb
# POST /speech_balloon_templates
# POST /speech_balloon_templates.json
def create
- @speech_balloon_template = SpeechBalloonTemplate.new(params[:speech_balloon_template])
- if em = validate_param(params[:speech_balloon_template])
- respond_to do |format|
- format.json { render json: em, status: :unprocessable_entity }
- end
- else
- respond_to do |format|
- if @speech_balloon_template.save
- format.html { redirect_to @speech_balloon_template, notice: 'Speech balloon was successfully created.' }
- format.json { render json: @speech_balloon_template, status: :created, location: @speech_balloon_template }
- else
- format.html { render action: "new" }
- format.json { render json: @speech_balloon_template.errors, status: :unprocessable_entity }
- end
- end
- end
end
# DELETE /speech_balloon_templates/1