Class: StaticBlocks::StaticBlocksController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- StaticBlocks::StaticBlocksController
- Defined in:
- app/controllers/static_blocks/static_blocks_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /static_blocks POST /static_blocks.json.
-
#destroy ⇒ Object
DELETE /static_blocks/1 DELETE /static_blocks/1.json.
-
#edit ⇒ Object
GET /static_blocks/1/edit.
- #export ⇒ Object
- #export_translations ⇒ Object
- #import ⇒ Object
- #import_translations ⇒ Object
-
#index ⇒ Object
GET /static_blocks GET /static_blocks.json.
-
#new ⇒ Object
GET /static_blocks/new GET /static_blocks/new.json.
-
#show ⇒ Object
GET /static_blocks/1 GET /static_blocks/1.json.
-
#update ⇒ Object
PUT /static_blocks/1 PUT /static_blocks/1.json.
Instance Method Details
#create ⇒ Object
POST /static_blocks POST /static_blocks.json
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/controllers/static_blocks/static_blocks_controller.rb', line 93 def create @static_block = StaticBlock.new(params[:static_block]) respond_to do |format| if @static_block.save format.html { redirect_to @static_block, notice: 'Static block was successfully created.' } format.json { render json: @static_block, status: :created, location: @static_block } else format.html { render action: "new" } format.json { render json: @static_block.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /static_blocks/1 DELETE /static_blocks/1.json
125 126 127 128 129 130 131 132 133 |
# File 'app/controllers/static_blocks/static_blocks_controller.rb', line 125 def destroy @static_block = StaticBlock.find(params[:id]) @static_block.destroy respond_to do |format| format.html { redirect_to static_blocks_url } format.json { head :no_content } end end |
#edit ⇒ Object
GET /static_blocks/1/edit
87 88 89 |
# File 'app/controllers/static_blocks/static_blocks_controller.rb', line 87 def edit @static_block = StaticBlock.find(params[:id]) end |
#export ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'app/controllers/static_blocks/static_blocks_controller.rb', line 6 def export t = Time.now.strftime('%Y%m%d%H%M%S') filename = "static-blocks-#{t}.csv" respond_to do |format| format.csv do send_data StaticBlock.to_csv, :filename => filename end end end |
#export_translations ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/static_blocks/static_blocks_controller.rb', line 16 def export_translations t = Time.now.strftime('%Y%m%d%H%M%S') filename = "static-blocks-translations-#{t}.csv" respond_to do |format| format.csv do send_data StaticBlock.translations_to_csv, :filename => filename end end end |
#import ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/static_blocks/static_blocks_controller.rb', line 26 def import if params[:file].nil? redirect_to root_url flash[:error] = "You did not attach a file." elsif params[:file].original_filename.include? 'translations' redirect_to root_url flash[:error] = "Wrong file. You uploaded the translations." else StaticBlock.import(params[:file]) redirect_to root_url, notice: "Static Blocks imported" end end |
#import_translations ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/static_blocks/static_blocks_controller.rb', line 39 def import_translations if params[:file].nil? redirect_to root_url flash[:error] = "You did not attach a file." elsif params[:file].original_filename.include? 'translations' StaticBlock.import_translations(params[:file]) redirect_to root_url, notice: "Static Block translations imported" else redirect_to root_url flash[:error] = "Wrong file. You uploaded the default static blocks." end end |
#index ⇒ Object
GET /static_blocks GET /static_blocks.json
54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/static_blocks/static_blocks_controller.rb', line 54 def index @search = StaticBlock.order('title asc').search(params[:q]) @static_blocks = @search.result.per_page_kaminari(params[:page]).per(10) respond_to do |format| format.html # index.html.erb format.json { render json: @static_blocks } end end |
#new ⇒ Object
GET /static_blocks/new GET /static_blocks/new.json
77 78 79 80 81 82 83 84 |
# File 'app/controllers/static_blocks/static_blocks_controller.rb', line 77 def new @static_block = StaticBlock.new respond_to do |format| format.html # new.html.erb format.json { render json: @static_block } end end |
#show ⇒ Object
GET /static_blocks/1 GET /static_blocks/1.json
66 67 68 69 70 71 72 73 |
# File 'app/controllers/static_blocks/static_blocks_controller.rb', line 66 def show @static_block = StaticBlock.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @static_block } end end |
#update ⇒ Object
PUT /static_blocks/1 PUT /static_blocks/1.json
109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/controllers/static_blocks/static_blocks_controller.rb', line 109 def update @static_block = StaticBlock.find(params[:id]) respond_to do |format| if @static_block.update_attributes(params[:static_block]) format.html { redirect_to @static_block, notice: 'Static block was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @static_block.errors, status: :unprocessable_entity } end end end |