page model and starting resource
This commit is contained in:
parent
58259c4b15
commit
beaae6cb32
@ -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
|
@ -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
|
||||
|
10
app/views/cms/pages/_form.html.haml
Normal file
10
app/views/cms/pages/_form.html.haml
Normal 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'
|
7
app/views/cms/pages/edit.html.haml
Normal file
7
app/views/cms/pages/edit.html.haml
Normal file
@ -0,0 +1,7 @@
|
||||
%h1 Editing cms_page
|
||||
|
||||
= render 'form'
|
||||
|
||||
= link_to 'Show', @cms_page
|
||||
\|
|
||||
= link_to 'Back', cms_pages_path
|
21
app/views/cms/pages/index.html.haml
Normal file
21
app/views/cms/pages/index.html.haml
Normal 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
|
5
app/views/cms/pages/new.html.haml
Normal file
5
app/views/cms/pages/new.html.haml
Normal file
@ -0,0 +1,5 @@
|
||||
%h1 New cms_page
|
||||
|
||||
= render 'form'
|
||||
|
||||
= link_to 'Back', cms_pages_path
|
6
app/views/cms/pages/show.html.haml
Normal file
6
app/views/cms/pages/show.html.haml
Normal file
@ -0,0 +1,6 @@
|
||||
%p#notice= notice
|
||||
|
||||
|
||||
= link_to 'Edit', edit_cms_page_path(@cms_page)
|
||||
\|
|
||||
= link_to 'Back', cms_pages_path
|
@ -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 => "/"}
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user