Class: Assetable::AssetsController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Assetable::AssetsController
- Defined in:
- app/controllers/assetable/assets_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Create a new asset.
-
#edit ⇒ Object
Edit an asset will return the edit form.
- #index ⇒ Object
-
#insert ⇒ Object
Insert assets into a gallery or uploader.
-
#permitted_params ⇒ Object
Permitted params for the model.
-
#update ⇒ Object
Update an asset.
Instance Method Details
#create ⇒ Object
Create a new asset
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/assetable/assets_controller.rb', line 19 def create # Get the content type content_type = params[:file].content_type asset_params = {name: params[:file].original_filename, filename: params[:file]} # Create the appropriate model if content_type.split("/").first == "image" @asset = Assetabler::Image.new(asset_params) elsif content_type.split("/").first == "video" @asset = Assetabler::Video.new(asset_params) elsif content_type.split("/").first == "application" @asset = Assetabler::Document.new(asset_params) end # Return @fieldname = params[:fieldname] @uploader_id = params[:uploader_id] if @asset.errors.empty? and @asset.save render :create else render :error end end |
#edit ⇒ Object
Edit an asset will return the edit form
44 45 46 |
# File 'app/controllers/assetable/assets_controller.rb', line 44 def edit @asset = Assetabler::Asset.find(params[:id]) end |
#index ⇒ Object
5 6 7 8 9 |
# File 'app/controllers/assetable/assets_controller.rb', line 5 def index @assets = Assetabler::Asset.page(params[:page]).per(20) @fieldname = params[:fieldname] @uploader_id = params[:uploader_id] end |
#insert ⇒ Object
Insert assets into a gallery or uploader
12 13 14 15 16 |
# File 'app/controllers/assetable/assets_controller.rb', line 12 def insert @fieldname = params[:fieldname] @uploader_id = params[:uploader_id] @assets = Assetabler::Asset.find(params[:asset_ids]) end |
#permitted_params ⇒ Object
Permitted params for the model
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/assetable/assets_controller.rb', line 55 def permitted_params params.require(params[:asset_type].underscore.to_sym).permit( :name, :filename, :body, :content_type, :width, :height, :asset_type, :ratio ) end |
#update ⇒ Object
Update an asset
49 50 51 52 |
# File 'app/controllers/assetable/assets_controller.rb', line 49 def update @asset = Assetabler::Asset.find(params[:id]) @asset.update_attributes(permitted_params) end |