page model and starting resource

This commit is contained in:
Torsten 2022-11-25 14:46:49 +02:00
parent 58259c4b15
commit beaae6cb32
11 changed files with 79 additions and 6 deletions

View File

@ -1,6 +1,6 @@
module Cms
class ImageController < CmsController
class ImagesController < CmsController
@@root = "app/assets/images/cms/"
@@files = Set.new Dir.new(Rails.root + @@root).children

View File

@ -1,2 +1,27 @@
class Cms::Page < ActiveModel
module Cms
class Page
include ActiveModel::API
include ActiveModel::Conversion
@@files = Set.new Dir.new(Rails.root.join("cms")).children
attr_reader :name
def id
@name
end
def persisted?
false
end
def initialize file_name
@name = file_name.split(".").first
@content = YAML.load_file(Rails.root.join("cms" , file_name))
end
def self.all
@@files.collect{ |file| Page.new(file) }
end
end
end

View File

@ -0,0 +1,10 @@
= form_for @cms_page do |f|
- if @cms_page.errors.any?
#error_explanation
%h2= "#{pluralize(@cms_page.errors.count, "error")} prohibited this cms_page from being saved:"
%ul
- @cms_page.errors.full_messages.each do |message|
%li= message
.actions
= f.submit 'Save'

View File

@ -0,0 +1,7 @@
%h1 Editing cms_page
= render 'form'
= link_to 'Show', @cms_page
\|
= link_to 'Back', cms_pages_path

View File

@ -0,0 +1,21 @@
%h1 Listing cms_pages
%table
%thead
%tr
%th
%th
%th
%tbody
- @cms_pages.each do |cms_page|
%tr
=cms_page.id
%tr
%td= link_to 'Show', cms_page
%td= #link_to 'Edit', edit_cms_page_path(cms_page)
%td= link_to 'Destroy', cms_page, method: :delete, data: { confirm: 'Are you sure?' }
%br
= link_to 'New Page', new_cms_page_path

View File

@ -0,0 +1,5 @@
%h1 New cms_page
= render 'form'
= link_to 'Back', cms_pages_path

View File

@ -0,0 +1,6 @@
%p#notice= notice
= link_to 'Edit', edit_cms_page_path(@cms_page)
\|
= link_to 'Back', cms_pages_path

View File

@ -23,10 +23,10 @@
%nav.hidden.md:block{"aria-label" => "Site Nav"}
%ul.flex.items-center.gap-6.text-sm
%li
%a.text-gray-500.transition{:class => "hover:text-gray-500/75", :href => "/cms/page/"}
%a.text-gray-500.transition{:class => "hover:text-gray-500/75", :href => cms_pages_path}
Pages
%li
%a.text-gray-500.transition{:class => "hover:text-gray-500/75", :href => "/cms/image/"}
%a.text-gray-500.transition{:class => "hover:text-gray-500/75", :href => cms_images_path}
Images
%li
%a.text-gray-500.transition{:class => "hover:text-gray-500/75", :href => "/"}

View File

@ -2,8 +2,7 @@ Rails.application.routes.draw do
namespace :cms do
resources :pages
resources :image
resources :page
resources :images
end
get 'pages/:id' , to: 'high_voltage/pages#show', id: 'index'