poder crear un archivo nuevo sin traducciones
This commit is contained in:
parent
11bb3273aa
commit
adfe01e11f
3 changed files with 7 additions and 4 deletions
|
@ -17,13 +17,13 @@ class PostsController < ApplicationController
|
||||||
def new
|
def new
|
||||||
@lang = find_lang
|
@lang = find_lang
|
||||||
@site = find_site
|
@site = find_site
|
||||||
@post = Post.new(site: @site, front_matter: { date: Time.now })
|
@post = Post.new(site: @site, front_matter: { date: Time.now }, lang: @lang)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@lang = find_lang
|
@lang = find_lang
|
||||||
@site = find_site
|
@site = find_site
|
||||||
@post = Post.new(site: @site, front_matter: post_params.to_hash)
|
@post = Post.new(site: @site, front_matter: post_params.to_hash, lang: @lang)
|
||||||
|
|
||||||
if @post.save
|
if @post.save
|
||||||
redirect_to site_posts_path(@site, lang: @lang)
|
redirect_to site_posts_path(@site, lang: @lang)
|
||||||
|
|
|
@ -81,7 +81,10 @@ class Post
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_translations
|
def find_translations
|
||||||
get_front_matter('lang').map do |lang, id|
|
slugs = get_front_matter('lang')
|
||||||
|
return [] unless slugs.present?
|
||||||
|
|
||||||
|
slugs.map do |lang, id|
|
||||||
next if lang == @lang
|
next if lang == @lang
|
||||||
@site.posts_for(lang).find do |p|
|
@site.posts_for(lang).find do |p|
|
||||||
p.id == id
|
p.id == id
|
||||||
|
|
|
@ -121,7 +121,7 @@
|
||||||
= label_tag 'post_lang', t("posts.lang.#{lang}")
|
= label_tag 'post_lang', t("posts.lang.#{lang}")
|
||||||
= select_tag "post[lang][#{lang}]",
|
= select_tag "post[lang][#{lang}]",
|
||||||
options_for_select(@site.posts_for(lang).map { |p| [p.title, p.id] },
|
options_for_select(@site.posts_for(lang).map { |p| [p.title, p.id] },
|
||||||
@post.get_front_matter(:lang).dig(lang)),
|
@post.get_front_matter(:lang).try(:dig, lang)),
|
||||||
{ class: 'form-control select2' }
|
{ class: 'form-control select2' }
|
||||||
%small.text-muted.form-text= t('posts.lang_help')
|
%small.text-muted.form-text= t('posts.lang_help')
|
||||||
.form-group
|
.form-group
|
||||||
|
|
Loading…
Reference in a new issue