Class: Admin::HtmlAssetController
- Inherits:
-
AdminController
- Object
- AdminController
- Admin::HtmlAssetController
- Defined in:
- app/controllers/admin/html_asset_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
-
#serve ⇒ Object
replace with model which writes itself to File system and is served up by webserver.
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/admin/html_asset_controller.rb', line 22 def create add_sid(:html_asset) @asset = HtmlAsset.new(params[:html_asset]) @asset.user_id = current_user.id @asset.body = HtmlAsset.default_body(@asset.file_type) if @asset.save Activity.add(_sid, "Create '#{@asset.name}' #{@asset.file_type.upcase}", current_user.id, "HTML Asset") redirect_to "/admin/html_assets" else setup_index render "index" end end |
#destroy ⇒ Object
69 70 71 72 73 74 75 |
# File 'app/controllers/admin/html_asset_controller.rb', line 69 def destroy @html_asset = HtmlAsset.find_sys_id(_sid, params[:id]) HtmlAsset.delete_all("id = #{params[:id]} and system_id = #{_sid}") Activity.add(_sid, "Delete '#{@html_asset.name}' #{@html_asset.file_type.upcase}", current_user.id, "HTML Asset") redirect_to "/admin/html_assets" end |
#index ⇒ Object
5 6 7 |
# File 'app/controllers/admin/html_asset_controller.rb', line 5 def index setup_index end |
#serve ⇒ Object
replace with model which writes itself to File system and is served up by webserver
10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/admin/html_asset_controller.rb', line 10 def serve name,stamp = params[:path].split('-') asset = HtmlAsset.fetch(_sid, name.downcase, params[:format]) response.headers['Content-Type'] = "text/#{asset.file_type}" response.headers['Cache-Control'] = 'max-age=31536000, public' response.headers["Expires"] = CGI.rfc1123_date(Time.now + 360.days) mime_type = Mime::Type.lookup_by_extension(asset.file_type) content_type = mime_type.to_s unless mime_type.nil? render :inline=>asset.compiled, :type=>:erb, :layout=>false, :mime_type => content_type end |
#show ⇒ Object
36 37 38 |
# File 'app/controllers/admin/html_asset_controller.rb', line 36 def show @html_asset = HtmlAsset.find_sys_id(_sid, params[:id]) end |
#update ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/admin/html_asset_controller.rb', line 40 def update @html_asset = HtmlAsset.find_sys_id(_sid, params[:id]) add_sid(:html_asset) @html_asset.body = params[:html_asset][:body] @html_asset.file_type = params[:html_asset][:file_type] begin @html_asset.generate_compiled rescue Sass::SyntaxError => error @html_asset = HtmlAsset.new(params[:html_asset]) @html_asset.id = params[:id] @html_asset.system_id = _sid flash[:notice] = error.to_s render "show" return end if @html_asset.update_attributes(params[:html_asset]) Activity.add(_sid, "Edit '#{@html_asset.name}' #{@html_asset.file_type.upcase}", current_user.id, "HTML Asset") HtmlAsset.clear_cache(@html_asset) if params[:submit_button]=="save-and-edit-again" redirect_to "/admin/html_asset/#{@html_asset.id}#editor" else redirect_to "/admin/html_assets" end else render "show" end end |