app/controllers/spina/admin/pages_controller.rb in spina-0.8.3 vs app/controllers/spina/admin/pages_controller.rb in spina-0.9.0

- old
+ new

@@ -1,11 +1,12 @@ module Spina module Admin class PagesController < AdminController - before_filter :set_breadcrumb - before_filter :set_tabs, only: [:new, :create, :edit, :update] + before_action :set_breadcrumb + before_action :set_tabs, only: [:new, :create, :edit, :update] + before_action :set_locale authorize_resource class: Page layout "spina/admin/website" @@ -17,17 +18,16 @@ @page = Page.new if current_theme.new_page_templates.any? { |template| template[0] == params[:view_template] } @page.view_template = params[:view_template] end add_breadcrumb I18n.t('spina.pages.new') - @page_parts = current_theme.config.page_parts.map { |page_part| @page.page_part(page_part) } + @page_parts = current_theme.page_parts.map { |page_part| @page.page_part(page_part) } end def create @page = Page.new(page_params) add_breadcrumb I18n.t('spina.pages.new') - # @page.set_materialized_path if @page.save redirect_to spina.edit_admin_page_url(@page) else @page_parts = @page.page_parts render :new @@ -35,19 +35,22 @@ end def edit @page = Page.find(params[:id]) add_breadcrumb @page.title - @page_parts = current_theme.config.page_parts.map { |page_part| @page.page_part(page_part) } + @page_parts = current_theme.page_parts.map { |page_part| @page.page_part(page_part) } end def update + I18n.locale = params[:locale] || I18n.default_locale @page = Page.find(params[:id]) add_breadcrumb @page.title respond_to do |format| if @page.update_attributes(page_params) - format.html { redirect_to spina.edit_admin_page_url(@page) } + @page.touch + I18n.locale = I18n.default_locale + format.html { redirect_to spina.edit_admin_page_url(@page, params: {locale: @locale}) } format.js else format.html do @page_parts = @page.page_parts render :edit @@ -70,10 +73,14 @@ redirect_to spina.admin_pages_url end private + def set_locale + @locale = params[:locale] || I18n.default_locale + end + def set_breadcrumb add_breadcrumb I18n.t('spina.website.pages'), spina.admin_pages_path end def set_tabs @@ -92,10 +99,10 @@ end end end def page_params - params.require(:page).permit! + params.require(:page).permit!.merge(locale: params[:locale] || I18n.default_locale) end end end end