Class: Trance::Base
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Trance::Base
- Defined in:
- lib/trance/base.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #init ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
- #upload_create ⇒ Object
- #upload_destroy ⇒ Object
Instance Method Details
#create ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/trance/base.rb', line 40 def create @row = @model.new(params[@singular]) respond_to do |format| if @row.save format.html { redirect_to @row, notice: t('custom.successfully_created', :model => @model_h1) } format.json { render json: @row, status: :created, location: @row } else format.html { render :inline => new_view, :layout => true } format.json { render json: @row.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/trance/base.rb', line 66 def destroy @row = @model.find(params[:id]) @row.destroy respond_to do |format| format.html { redirect_to :action => 'index' } format.json { head :no_content } end end |
#edit ⇒ Object
33 34 35 36 37 38 |
# File 'lib/trance/base.rb', line 33 def edit @row = @model.find(params[:id]) respond_to do |format| format.html { render :inline => edit_view, :layout => _grid_layout } end end |
#index ⇒ Object
10 11 12 13 14 15 |
# File 'lib/trance/base.rb', line 10 def index respond_to do |format| format.html { render :inline => _index_view, :layout => _grid_layout } format.json { render :json => _grid_fetch } end end |
#init ⇒ Object
171 172 173 |
# File 'lib/trance/base.rb', line 171 def init end |
#new ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/trance/base.rb', line 25 def new @row = @model.new respond_to do |format| format.html { render :inline => new_view, :layout => _grid_layout } format.json { render json: @row } end end |
#show ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/trance/base.rb', line 17 def show @row = @model.find(params[:id]) respond_to do |format| format.html { render :inline => show_view, :layout => _grid_layout } format.json { render json: @row } end end |
#update ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/trance/base.rb', line 53 def update @row = @model.find(params[:id]) respond_to do |format| if @row.update_attributes(params[@singular]) format.html { redirect_to @row, notice: t('custom.successfully_updated', :model => @model_h1) } format.json { head :no_content } else format.html { render :inline => edit_view, :layout => true } format.json { render json: @row.errors, status: :unprocessable_entity } end end end |
#upload_create ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/trance/base.rb', line 75 def upload_create NoticiasController::layout nil if params[:filedata] img = params[:filedata][:image] tmp = RAILS_ROOT + '/tmp/uploads/' + Digest::SHA1.hexdigest(Time.now.to_i.to_s) + '.dat' File::copy_stream img.tempfile.path, tmp session[:upload] = { :original_filename => img.original_filename, :content_type => img.content_type, :tempfile => File::basename(tmp), :size => File::size(tmp) } @upload = session[:upload] render :inline => "<% if @upload %>\n\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n<html dir=ltr= \"pt-br\" xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n <title><%= @title.nil? ? @head_title : @title + @title_separator + @head_title %></title>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n <%= javascript_include_tag 'jquery' %>\n</head>\n<body>\n <div>\n\n\n<script type=\"text/javascript\">\nvar upload = {};\n\nupload.cancel = function() {\n $.ajax({\n type: 'post',\n url: 'upload-destroy',\n success: function(responseText) {\n parent.$('#upload-item-0').remove();\n }\n });\n};\n\nupload.add = function (data) {\n var item = $('<div>').attr({\n 'class': 'upload-item',\n 'id': 'upload-item-0'\n });\n var text = data.original_filename + ' (' + (data.size / 1024).toFixed(2) + 'KB)';\n var name = $('<span>').attr('class', 'upload-name').html(text);\n var cancel = $('<a>').attr({\n 'class': 'upload-cancel ui-state-default ui-corner-all',\n 'href': 'javascript:void(0);'\n }).click(function(evt){\n upload.cancel();\n });\n var icon = $('<span>').attr('class', 'ui-icon ui-icon-closethick');\n var input = $('<input>').attr({\n 'id': 'upload-input-0',\n 'name': '\#{params[:filedata][:name]}',\n 'type': 'hidden',\n 'value': data.tempfile\n });\n\n item.append(name).append(cancel).append(input);\n cancel.append(icon);\n\n parent.$('#upload-queue-0').append(item);\n parent.$('#upload-form-0').trigger('reset');\n}\n\nparent.upload = upload;\n\nupload.add(<%= raw @upload.to_json %>);\n</script>\n\n\n </div>\n</body>\n</html>\n\n<% end %>\n" end end |
#upload_destroy ⇒ Object
163 164 165 166 167 168 169 |
# File 'lib/trance/base.rb', line 163 def upload_destroy filename = RAILS_ROOT + '/tmp/uploads/' + session[:upload][:tempfile] File::unlink filename session[:upload] = nil head :no_content end |