Class: Comfy::Admin::Cms::SnippetsController
- Inherits:
-
BaseController
- Object
- BaseController
- Comfy::Admin::Cms::SnippetsController
- Defined in:
- app/controllers/comfy/admin/cms/snippets_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #reorder ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/controllers/comfy/admin/cms/snippets_controller.rb', line 19 def create @snippet.save! flash[:success] = I18n.t('comfy.admin.cms.snippets.created') redirect_to :action => :edit, :id => @snippet rescue ActiveRecord::RecordInvalid flash.now[:danger] = I18n.t('comfy.admin.cms.snippets.creation_failure') render :action => :new end |
#destroy ⇒ Object
37 38 39 40 41 |
# File 'app/controllers/comfy/admin/cms/snippets_controller.rb', line 37 def destroy @snippet.destroy flash[:success] = I18n.t('comfy.admin.cms.snippets.deleted') redirect_to :action => :index end |
#edit ⇒ Object
15 16 17 |
# File 'app/controllers/comfy/admin/cms/snippets_controller.rb', line 15 def edit @snippet.attributes = snippet_params end |
#index ⇒ Object
6 7 8 9 |
# File 'app/controllers/comfy/admin/cms/snippets_controller.rb', line 6 def index return redirect_to :action => :new if @site.snippets.count == 0 @snippets = @site.snippets.includes(:categories).for_category(params[:category]) end |
#new ⇒ Object
11 12 13 |
# File 'app/controllers/comfy/admin/cms/snippets_controller.rb', line 11 def new render end |
#reorder ⇒ Object
43 44 45 46 47 48 |
# File 'app/controllers/comfy/admin/cms/snippets_controller.rb', line 43 def reorder (params[:comfy_cms_snippet] || []).each_with_index do |id, index| ::Comfy::Cms::Snippet.where(:id => id).update_all(:position => index) end render :nothing => true end |
#update ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/controllers/comfy/admin/cms/snippets_controller.rb', line 28 def update @snippet.update_attributes!(snippet_params) flash[:success] = I18n.t('comfy.admin.cms.snippets.updated') redirect_to :action => :edit, :id => @snippet rescue ActiveRecord::RecordInvalid flash.now[:danger] = I18n.t('comfy.admin.cms.snippets.update_failure') render :action => :edit end |