1 class SpeachBalloonsController < ApplicationController
2 before_filter :authenticate_author!, :only => [:index]
3 before_filter :authenticate_admin!, :except => [:index]
9 bl = ft[:border_limit].to_i
10 tl = ft[:tail_limit].to_i
11 if bl * tl == ft[:balloon_templates_attributes].size
19 ft[:balloon_templates_attributes].each do |k, t|
20 flag[t[:border].to_i - 1][t[:tail].to_i - 1] = nil
22 if flag.flatten.compact.size == 0
24 res = "invalid variation"
27 res = "invalid template size"
32 public # GET /speach_balloons
33 # GET /speach_balloons.json
35 @speach_balloons = SpeachBalloon.all
37 respond_to do |format|
38 format.html # index.html.erb
39 format.json { render json: @speach_balloons }
43 # GET /speach_balloons/1
44 # GET /speach_balloons/1.json
46 @speach_balloon = SpeachBalloon.find(params[:id], include: {:balloon_templates => :speach_templates})
48 respond_to do |format|
49 format.html # show.html.erb
51 render :json => @speach_balloon.to_json(include: {
52 :balloon_templates => {:include => :speach_templates}
56 render :json => "callback(" + @speach_balloon.to_json(include: {
57 :balloon_templates => {:include => :speach_templates}
63 # GET /speach_balloons/new
64 # GET /speach_balloons/new.json
66 @speach_balloon = SpeachBalloon.new
68 respond_to do |format|
69 format.html # new.html.erb
70 format.json { render json: @speach_balloon }
74 # GET /speach_balloons/1/edit
76 @speach_balloon = SpeachBalloon.find(params[:id])
79 # POST /speach_balloons
80 # POST /speach_balloons.json
82 @speach_balloon = SpeachBalloon.new(params[:speach_balloon])
83 if em = validate_param(params[:speach_balloon])
84 respond_to do |format|
85 format.json { render json: em, status: :unprocessable_entity }
88 respond_to do |format|
89 if @speach_balloon.save
90 format.html { redirect_to @speach_balloon, notice: 'Speach balloon was successfully created.' }
91 format.json { render json: @speach_balloon, status: :created, location: @speach_balloon }
93 format.html { render action: "new" }
94 format.json { render json: @speach_balloon.errors, status: :unprocessable_entity }
100 # PUT /speach_balloons/1
101 # PUT /speach_balloons/1.json
103 @speach_balloon = SpeachBalloon.find(params[:id])
105 respond_to do |format|
106 if @speach_balloon.update_attributes(params[:speach_balloon])
107 format.html { redirect_to @speach_balloon, notice: 'Speach balloon was successfully updated.' }
108 format.json { head :ok }
110 format.html { render action: "edit" }
111 format.json { render json: @speach_balloon.errors, status: :unprocessable_entity }
116 # DELETE /speach_balloons/1
117 # DELETE /speach_balloons/1.json
119 @speach_balloon = SpeachBalloon.find(params[:id])
120 @speach_balloon.destroy
122 respond_to do |format|
123 format.html { redirect_to speach_balloons_url }
124 format.json { head :ok }