actualizar sitios

This commit is contained in:
f 2019-07-12 21:20:36 -03:00
parent 3a3dd7a2de
commit 6c25e35cd7
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
8 changed files with 64 additions and 8 deletions

View file

@ -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

View file

@ -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

View 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
View 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')

View file

@ -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')

View file

@ -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:

View file

@ -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:

View file

@ -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