Class: Smithy::PageContentsController
- Inherits:
-
BaseController
- Object
- ApplicationController
- BaseController
- Smithy::PageContentsController
- Includes:
- Liquid::Rendering
- Defined in:
- app/controllers/smithy/page_contents_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #new ⇒ Object
- #order ⇒ Object
- #preview ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/smithy/page_contents_controller.rb', line 17 def create @page_content = Smithy::PageContent.new # we have to ensure that the content_block_type gets added before the content_block_attributes # see PageContent#content_block_attributes= @page_content.content_block_type = filtered_params[:content_block_type] @page_content.attributes = filtered_params # @page_content.content_block_attributes = params[:page_content][:content_block_attributes] if params[:page_content][:content_block_attributes] @page_content.page = @page @page_content.save respond_with @page_content do |format| format.html { @page_content.persisted? ? redirect_to(edit_page_content_path(@page.id, @page_content)) : render(:action => 'new') } end end |
#destroy ⇒ Object
45 46 47 48 49 50 |
# File 'app/controllers/smithy/page_contents_controller.rb', line 45 def destroy @page_content.destroy respond_with @page_content do |format| format.html { redirect_to edit_page_path(@page.id), :notice => "Your content was deleted from the page" } end end |
#edit ⇒ Object
31 32 33 |
# File 'app/controllers/smithy/page_contents_controller.rb', line 31 def edit respond_with @page_content end |
#new ⇒ Object
12 13 14 15 |
# File 'app/controllers/smithy/page_contents_controller.rb', line 12 def new @page_content = Smithy::PageContent.new(filtered_params) @page_content.label = [@page.title, @page_content.container.titleize].join(' - ') unless @page_content.label? end |
#order ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/smithy/page_contents_controller.rb', line 58 def order params[:order].each_with_index do |page_content_id, index| page_content = @page.contents.find(page_content_id) page_content.update_attribute(:position, index) end if request.xhr? render :nothing => true, :status => 200 else redirect_to edit_page_path(@page.id) end end |
#preview ⇒ Object
52 53 54 55 56 |
# File 'app/controllers/smithy/page_contents_controller.rb', line 52 def preview respond_with @page_content do |format| format.html { render :text => @page_content.render(liquid_context), :layout => 'smithy/modal' } end end |
#update ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/smithy/page_contents_controller.rb', line 35 def update @page_content = Smithy::PageContent.find(params[:id]) # @page_content.content_block_attributes = params[:page_content][:content_block_attributes] @saved = @page_content.update_attributes(filtered_params) flash.notice = "Your content was saved" if @saved respond_with @page_content do |format| format.html { @saved ? redirect_to(edit_page_path(@page.id)) : render(:action => "edit") } end end |