actualizar sitios
This commit is contained in:
parent
3a3dd7a2de
commit
6c25e35cd7
8 changed files with 64 additions and 8 deletions
|
@ -38,6 +38,22 @@ class SitesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@site = find_site
|
||||
authorize @site
|
||||
end
|
||||
|
||||
def update
|
||||
@site = find_site
|
||||
authorize @site
|
||||
|
||||
if @site.update(site_params)
|
||||
redirect_to sites_path
|
||||
else
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
# Envía un archivo del directorio público de Jekyll
|
||||
def send_public_file
|
||||
authorize Site
|
||||
|
|
|
@ -23,6 +23,8 @@ class Site < ApplicationRecord
|
|||
# de crearlo
|
||||
after_initialize :load_jekyll!
|
||||
after_create :load_jekyll!
|
||||
# Cambiar el nombre del directorio
|
||||
before_update :update_name!
|
||||
|
||||
attr_accessor :jekyll, :collections
|
||||
|
||||
|
@ -38,7 +40,11 @@ class Site < ApplicationRecord
|
|||
#
|
||||
# Equivale a _sites + nombre
|
||||
def path
|
||||
@path ||= File.join(Site.site_path, name)
|
||||
File.join(Site.site_path, name)
|
||||
end
|
||||
|
||||
def old_path
|
||||
File.join(Site.site_path, name_was)
|
||||
end
|
||||
|
||||
# Este sitio acepta invitadxs?
|
||||
|
@ -370,4 +376,10 @@ class Site < ApplicationRecord
|
|||
def remove_directories!
|
||||
FileUtils.rm_rf path
|
||||
end
|
||||
|
||||
def update_name!
|
||||
return unless name_changed?
|
||||
|
||||
FileUtils.mv old_path, path
|
||||
end
|
||||
end
|
||||
|
|
6
app/views/sites/_form.haml
Normal file
6
app/views/sites/_form.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
= form_for @site do |f|
|
||||
.form-group
|
||||
= f.label :name
|
||||
= f.text_field :name, class: 'form-control'
|
||||
.form-group
|
||||
= f.submit submit, class: 'btn btn-success'
|
10
app/views/sites/edit.haml
Normal file
10
app/views/sites/edit.haml
Normal file
|
@ -0,0 +1,10 @@
|
|||
.row
|
||||
.col
|
||||
= render 'layouts/breadcrumb',
|
||||
crumbs: [link_to(t('sites.index'), sites_path),
|
||||
t('.title', site: @site.name)]
|
||||
.row
|
||||
.col
|
||||
%h1= t('.title', site: @site.name)
|
||||
|
||||
= render 'form', submit: t('.submit')
|
|
@ -1,14 +1,9 @@
|
|||
.row
|
||||
.col
|
||||
= render 'layouts/breadcrumb',
|
||||
crumbs: [ link_to(t('sites.index'), sites_path), t('.title') ]
|
||||
crumbs: [link_to(t('sites.index'), sites_path), t('.title')]
|
||||
.row
|
||||
.col
|
||||
%h1= t('.title')
|
||||
|
||||
= form_for @site do |f|
|
||||
.form-group
|
||||
= f.label :name
|
||||
= f.text_field :name, class: 'form-control'
|
||||
.form-group
|
||||
= f.submit t('.submit'), class: 'btn btn-success'
|
||||
= render 'form', submit: t('.submit')
|
||||
|
|
|
@ -155,6 +155,9 @@ en:
|
|||
new:
|
||||
title: 'Create site'
|
||||
submit: 'Create site'
|
||||
edit:
|
||||
title: 'Edit %{site}'
|
||||
submit: 'Save changes'
|
||||
footer:
|
||||
powered_by: 'is developed by'
|
||||
templates:
|
||||
|
|
|
@ -160,6 +160,9 @@ es:
|
|||
new:
|
||||
title: 'Crear un sitio'
|
||||
submit: 'Crear sitio'
|
||||
edit:
|
||||
title: 'Editar %{site}'
|
||||
submit: 'Guardar cambios'
|
||||
footer:
|
||||
powered_by: 'es desarrollada por'
|
||||
i18n:
|
||||
|
|
|
@ -61,4 +61,15 @@ class SiteTest < ActiveSupport::TestCase
|
|||
assert site.valid?
|
||||
assert !site.posts.empty?
|
||||
end
|
||||
|
||||
test 'se pueden renombrar' do
|
||||
@site = create :site
|
||||
path = @site.path
|
||||
|
||||
@site.update_attribute :name, SecureRandom.hex
|
||||
|
||||
assert_not_equal path, @site.path
|
||||
assert File.directory?(@site.path)
|
||||
assert_not File.directory?(path)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue