class Humpyard::AssetsController

Public Instance Methods

create() click to toggle source
   # File app/controllers/humpyard/assets_controller.rb
19 def create  
20   @asset = Humpyard::config.asset_types[params[:type]].new params[:asset]
21         
22   unless can? :create, @asset.asset
23     render :json => {
24       :status => :failed
25     }, :status => 403
26     return
27   end
28       
29   if @asset.save
30     @assets = Humpyard::Asset.all
31     render :json => {
32       :status => :ok,
33       :replace => [{
34         :element => "hy-asset-listview",
35         :content => render_to_string(:partial => "list.html", :locals => {:assets => @assets, :asset => @asset})
36       }],
37       :flash => {
38         :level => 'info',
39         :content => I18n.t('humpyard_form.flashes.create_success', :model => Humpyard::Asset.model_name.human)
40       }
41     }
42   else
43     render :json => {
44       :status => :failed, 
45       :errors => @asset.errors,
46       :flash => {
47         :level => 'error',
48         :content => I18n.t('humpyard_form.flashes.create_fail', :model => Humpyard::Asset.model_name.human)
49       }
50     }
51   end
52 end
destroy() click to toggle source
    # File app/controllers/humpyard/assets_controller.rb
115 def destroy
116   @asset = Humpyard::Asset.find(params[:id])
117   
118   authorize! :destroy, @asset  
119   
120   @asset.destroy
121 end
edit() click to toggle source
   # File app/controllers/humpyard/assets_controller.rb
54 def edit
55   @asset = Humpyard::Asset.find(params[:id]).content_data
56   
57   authorize! :update, @asset.asset
58   
59   render :partial => 'edit'
60 end
index() click to toggle source
  # File app/controllers/humpyard/assets_controller.rb
3 def index
4   @assets = Humpyard::Asset.all
5   
6   render :partial => 'index'
7 end
new() click to toggle source
   # File app/controllers/humpyard/assets_controller.rb
 9 def new     
10   @asset = Humpyard::config.asset_types[params[:type]].new()
11   
12   authorize! :create, @asset.asset 
13   
14   @asset_type = params[:type]
15   
16   render :partial => 'edit'
17 end
show() click to toggle source
    # File app/controllers/humpyard/assets_controller.rb
107 def show
108   @asset = Humpyard::Asset.find(params[:id]).content_data
109   
110   authorize! :show, @asset.asset
111   
112   render :partial => 'show'
113 end
update() click to toggle source
    # File app/controllers/humpyard/assets_controller.rb
 62 def update
 63   @asset = Humpyard::Asset.find(params[:id])
 64   if @asset 
 65     unless can? :update, @asset
 66       render :json => {
 67         :status => :failed
 68       }, :status => 403
 69       return
 70     end
 71 
 72     if @asset.content_data.update_attributes params[:asset]
 73       render :json => {
 74         :status => :ok,
 75         :replace => [
 76           { 
 77             :element => "hy-asset-listview-text-#{@asset.id}",
 78             :content => render_to_string(:partial =>'list_item.html', :locals => {:asset => @asset, :active => true})
 79           }
 80         ],
 81         :flash => {
 82           :level => 'info',
 83           :content => I18n.t('humpyard_form.flashes.update_success', :model => Humpyard::Asset.model_name.human)
 84         }
 85       }
 86     else
 87       render :json => {
 88         :status => :failed, 
 89         :errors => @asset.content_data.errors,
 90         :flash => {
 91           :level => 'error',
 92           :content => I18n.t('humpyard_form.flashes.update_fail', :model => Humpyard::Asset.model_name.human)
 93         }
 94       }
 95     end
 96   else
 97     render :json => {
 98       :status => :failed,
 99       :flash => {
100         :level => 'error',
101         :content => I18n.t('humpyard_form.flashes.not_found', :model => Humpyard::Asset.model_name.human)
102       }
103     }, :status => 404
104   end
105 end