Class: Admin::HtmlAssetController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/html_asset_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/admin/html_asset_controller.rb', line 10

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

#destroyObject



57
58
59
60
61
62
63
# File 'app/controllers/admin/html_asset_controller.rb', line 57

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

#indexObject



5
6
7
# File 'app/controllers/admin/html_asset_controller.rb', line 5

def index
  setup_index
end

#showObject



24
25
26
# File 'app/controllers/admin/html_asset_controller.rb', line 24

def show
  @html_asset = HtmlAsset.find_sys_id(_sid, params[:id])
end

#updateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/admin/html_asset_controller.rb', line 28

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