Skip to content

Commit

Permalink
adding custom pages
Browse files Browse the repository at this point in the history
  • Loading branch information
blueroot committed Apr 18, 2011
1 parent 7ffa986 commit 066d46a
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 41 deletions.
16 changes: 15 additions & 1 deletion app/controllers/pages_controller.rb
@@ -1,6 +1,20 @@
class PagesController < ApplicationController
inherit_resources

before_filter :build_section_pages

def build_section_pages
@page_links = Page.find(:all, :conditions => "section = '#{params[:section]}'", :order => "sort")
end

def index
@section = params[:section]
@page = Page.find(:first, :conditions => "section = '#{params[:section]}'", :order => "sort")
end

def about
@page = Page.find(:first, :conditions => "section = 'about'", :order => "sort")
end

protected

def collection
Expand Down
6 changes: 6 additions & 0 deletions app/models/page.rb
@@ -1,2 +1,8 @@
class Page < ActiveRecord::Base


def to_param
"#{id}-#{title.gsub(/[^a-z0-9]+/i, '-').downcase}"
end

end
7 changes: 7 additions & 0 deletions app/views/dashboard/_about_sidebar.html.erb
Expand Up @@ -4,5 +4,12 @@
<li><%= link_to "The Open Missouri Team", omteam_path %></li>
<li><%= link_to "Open Source Missouri", opensource_path %></li>
<li><%= link_to "Open Missouri FAQ", faq_path %></li>

<% unless @page_links.blank? %>
<% @page_links.each do |page| %>
<li><%= link_to page.title, page %></li>

<% end %>
<% end %>
</ul>
</div>
6 changes: 0 additions & 6 deletions app/views/pages/_form.html.erb

This file was deleted.

11 changes: 11 additions & 0 deletions app/views/pages/_sidebar.html.erb
@@ -0,0 +1,11 @@
<div id="sidebar_content">
<ul>

<% unless @page_links.blank? %>
<% @page_links.each do |page| %>
<li><%= link_to page.title, page_path(page.section, page) %></li>

<% end %>
<% end %>
</ul>
</div>
3 changes: 0 additions & 3 deletions app/views/pages/edit.html.erb

This file was deleted.

21 changes: 7 additions & 14 deletions app/views/pages/index.html.erb
@@ -1,16 +1,9 @@
<% title 'Listing pages' %>
<h1><%= @page.title %></h1>

<% unless @pages.blank? %>
<%= table_for(@pages) %>
<%= will_paginate(@pages) %>
<% else %>
<p>Now it's time to create some data here. To create new entry, please use the button below.</p>
<br /><br />
<% end %>

<br />

<p>
<%= link_to 'New Page', new_page_path, :class => 'button' %>
</p>
<div id="sidebar">
<%= render :partial => "sidebar"%>
</div>

<div id="content" class="clearfix">
<%= raw @page.body %>
</div>
3 changes: 0 additions & 3 deletions app/views/pages/new.html.erb

This file was deleted.

16 changes: 13 additions & 3 deletions app/views/pages/show.html.erb
@@ -1,5 +1,15 @@
<p id="notice"><%= notice %></p>
<h1><%= @page.title %></h1>

<div id="sidebar">
<%= render :partial => "sidebar"%>
</div>

<div id="content" class="clearfix">
<%= raw @page.body %>
</div>






<%= link_to 'Edit', edit_page_path(@page) %> |
<%= link_to 'Back', pages_path %>
23 changes: 15 additions & 8 deletions config/initializers/rails_admin.rb
Expand Up @@ -50,16 +50,23 @@
end

config.model Page do

list do
sort_by :sort
sort_reverse { false }

field :title
field :section
field :sort
field :published
end

#this is arbitrary

#edit do
# field :name
# field :section
# field :sort
# field :body do
# ckeditor true
# end
#end
edit do


end
end

end
Expand Down
8 changes: 7 additions & 1 deletion config/routes.rb
@@ -1,12 +1,18 @@
Rails3Base::Application.routes.draw do


resources :pages


match 'data_sets/feed', :to => 'data_sets#feed', :action => 'feed'

match 'suggest_a_data_set', :to => 'data_sets#suggest', :as => "suggest"
match 'suggest_thanks/:id', :to => 'data_sets#thanks', :as => "suggest_thanks"

match 'pages/:section/', :to => 'pages#index', :as => "section"
match 'pages/:section/:id', :to => 'pages#show', :as => "page"

resources :pages

resources :data_sets do
collection do
get :category
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20110414162834_add_pages_link_name.rb
@@ -0,0 +1,9 @@
class AddPagesLinkName < ActiveRecord::Migration
def self.up
add_column :pages, :link_name, :string
remove_column :pages, :body_html
end

def self.down
end
end
9 changes: 9 additions & 0 deletions db/migrate/20110414163646_add_pages_link_published.rb
@@ -0,0 +1,9 @@
class AddPagesLinkPublished < ActiveRecord::Migration
def self.up
add_column :pages, :published, :boolean, :default => true
end

def self.down
remove_column :pages, :published
end
end
5 changes: 3 additions & 2 deletions db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20110407055220) do
ActiveRecord::Schema.define(:version => 20110414163646) do

create_table "admins", :force => true do |t|
t.datetime "created_at"
Expand Down Expand Up @@ -101,11 +101,12 @@
create_table "pages", :force => true do |t|
t.string "title"
t.text "body"
t.text "body_html"
t.string "section"
t.integer "sort"
t.datetime "created_at"
t.datetime "updated_at"
t.string "link_name"
t.boolean "published", :default => true
end

create_table "rails_admin_histories", :force => true do |t|
Expand Down

0 comments on commit 066d46a

Please sign in to comment.