diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index aad3855d..d956fd2c 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -40,6 +40,22 @@ class PostsController < ApplicationController render layout: false end + # El formulario de un Post, si pasamos el uuid, estamos editando, sino + # estamos creando. + def form + uuid = params.permit(:uuid).try(:[], :uuid) + + @post = + if uuid.present? + site.indexed_posts.find_by!(post_id: uuid).post + else + # @todo Usar la base de datos + site.posts(lang: locale).build(layout: params.require(:layout)) + end + + render layout: false + end + def index authorize Post diff --git a/app/views/posts/form.haml b/app/views/posts/form.haml new file mode 100644 index 00000000..36d15fde --- /dev/null +++ b/app/views/posts/form.haml @@ -0,0 +1,7 @@ +-# + El formulario sin ninguna decoraciĆ³n, para incluir dentro de otros + elementos. + + @param :site [Site] + @param :post [Post] += render 'posts/form', site: @site, post: @post diff --git a/config/routes.rb b/config/routes.rb index be50fafd..45410782 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -103,6 +103,7 @@ Rails.application.routes.draw do get :'posts/new_array', to: 'posts#new_array' get :'posts/new_array_value', to: 'posts#new_array_value' get :'posts/new_related_post', to: 'posts#new_related_post' + get :'posts/form', to: 'posts#form' resources :posts do get 'p/:page', action: :index, on: :collection