mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
All done! Contact form works, about page now pulls content from database, opening up the possibility of having more pages.
This commit is contained in:
parent
4c86abbc6e
commit
2e83970fa9
1
Gemfile
1
Gemfile
@ -32,3 +32,4 @@ gem 'sqlite3-ruby', :require => 'sqlite3'
|
||||
gem 'typus', :git => 'git://github.com/fesplugas/typus.git'
|
||||
gem 'mini_exiftool'
|
||||
gem "will_paginate", "3.0.pre"
|
||||
gem 'rdiscount'
|
||||
@ -66,6 +66,7 @@ GEM
|
||||
rake (>= 0.8.4)
|
||||
thor (~> 0.14.0)
|
||||
rake (0.8.7)
|
||||
rdiscount (1.6.5)
|
||||
sqlite3-ruby (1.3.1)
|
||||
thor (0.14.3)
|
||||
treetop (1.4.8)
|
||||
@ -79,6 +80,7 @@ PLATFORMS
|
||||
DEPENDENCIES
|
||||
mini_exiftool
|
||||
rails (= 3.0.0)
|
||||
rdiscount
|
||||
sqlite3-ruby
|
||||
typus!
|
||||
will_paginate (= 3.0.pre)
|
||||
|
||||
2
app/controllers/admin/admin_users_controller.rb
Normal file
2
app/controllers/admin/admin_users_controller.rb
Normal file
@ -0,0 +1,2 @@
|
||||
class Admin::AdminUsersController < Admin::ResourcesController
|
||||
end
|
||||
2
app/controllers/admin/pages_controller.rb
Normal file
2
app/controllers/admin/pages_controller.rb
Normal file
@ -0,0 +1,2 @@
|
||||
class Admin::PagesController < Admin::ResourcesController
|
||||
end
|
||||
17
app/controllers/contacts_controller.rb
Normal file
17
app/controllers/contacts_controller.rb
Normal file
@ -0,0 +1,17 @@
|
||||
class ContactsController < ApplicationController
|
||||
layout "photos"
|
||||
|
||||
def new
|
||||
@contact = Contact.new(:id => 1)
|
||||
end
|
||||
|
||||
def create
|
||||
@contact = Contact.new(params[:contact])
|
||||
if @contact.save
|
||||
redirect_to(:new_contact, :notice => "Thanks for your email, I'll be in touch as soon as possible.")
|
||||
else
|
||||
flash[:alert] = "Please fill in fields marked in red."
|
||||
render :new
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -4,4 +4,8 @@ class PagesController < ApplicationController
|
||||
def index
|
||||
@photo = Photo.first(:order => 'RANDOM()')
|
||||
end
|
||||
|
||||
def about
|
||||
@content = Page.find_by_name('about')
|
||||
end
|
||||
end
|
||||
|
||||
2
app/helpers/contacts_helper.rb
Normal file
2
app/helpers/contacts_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module ContactsHelper
|
||||
end
|
||||
10
app/mailers/notifier.rb
Normal file
10
app/mailers/notifier.rb
Normal file
@ -0,0 +1,10 @@
|
||||
class Notifier < ActionMailer::Base
|
||||
default :from => "enquiries@danbarberphoto.com"
|
||||
|
||||
def contact_notification(sender)
|
||||
@sender = sender
|
||||
mail( :to => 'danbee@gmail.com',
|
||||
:from => sender.email,
|
||||
:subject => sender.subject)
|
||||
end
|
||||
end
|
||||
8
app/models/admin_user.rb
Normal file
8
app/models/admin_user.rb
Normal file
@ -0,0 +1,8 @@
|
||||
class AdminUser < ActiveRecord::Base
|
||||
|
||||
ROLE = Typus::Configuration.roles.keys.sort
|
||||
LANGUAGE = Typus.locales
|
||||
|
||||
enable_as_typus_user
|
||||
|
||||
end
|
||||
26
app/models/contact.rb
Normal file
26
app/models/contact.rb
Normal file
@ -0,0 +1,26 @@
|
||||
class Contact
|
||||
include ActiveModel::Validations
|
||||
|
||||
validates_presence_of :email, :name, :message
|
||||
|
||||
attr_accessor :id, :email, :subject, :name, :message
|
||||
|
||||
def initialize(attributes = {})
|
||||
attributes.each do |key, value|
|
||||
self.send("#{key}=", value)
|
||||
end
|
||||
@attributes = attributes
|
||||
end
|
||||
|
||||
def read_attribute_for_validation(key)
|
||||
@attributes[key]
|
||||
end
|
||||
|
||||
def save
|
||||
if self.valid?
|
||||
Notifier.contact_notification(self).deliver
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
8
app/models/page.rb
Normal file
8
app/models/page.rb
Normal file
@ -0,0 +1,8 @@
|
||||
require 'rdiscount'
|
||||
|
||||
class Page < ActiveRecord::Base
|
||||
def html
|
||||
markdown = Markdown.new(self.content, :smart)
|
||||
markdown.to_html
|
||||
end
|
||||
end
|
||||
14
app/views/contacts/index.html.erb
Normal file
14
app/views/contacts/index.html.erb
Normal file
@ -0,0 +1,14 @@
|
||||
<div class="sg-5 about">
|
||||
<%= link_to raw('<span>about</span>'), about_url %>
|
||||
</div>
|
||||
<div class="sg-5 portfolio">
|
||||
<%= link_to raw('<span>portfolio</span>'), :controller => 'categories' %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sg-17 contact-form">
|
||||
<% if flash[:notice] -%>
|
||||
<div id="notice"><%= flash[:notice] %></div>
|
||||
<% end -%>
|
||||
<p>Tel: 01752 546981</p>
|
||||
</div>
|
||||
46
app/views/contacts/new.html.erb
Normal file
46
app/views/contacts/new.html.erb
Normal file
@ -0,0 +1,46 @@
|
||||
<div class="sg-5 about">
|
||||
<%= link_to raw('<span>about</span>'), about_url %>
|
||||
</div>
|
||||
<div class="sg-5 portfolio">
|
||||
<%= link_to raw('<span>portfolio</span>'), :controller => 'categories' %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sg-17 contact-form">
|
||||
<%= form_for :contact, :url => { :action => 'create' } do |f| %>
|
||||
<% if flash[:notice] -%>
|
||||
<div id="notice"><%= flash[:notice] %></div>
|
||||
<% end -%>
|
||||
<% if flash[:alert] -%>
|
||||
<div id="alert"><%= flash[:alert] %></div>
|
||||
<% end -%>
|
||||
<p>Please use the form below to contact me.</p>
|
||||
<p>
|
||||
<%= f.label :name %>
|
||||
<%= f.text_field :name %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.label :email %>
|
||||
<%= f.text_field :email %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.label :subject %>
|
||||
<%= f.text_field :subject %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.label :message %>
|
||||
<%= f.text_area :message %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.label raw(' ') %>
|
||||
<%= f.submit 'Send Message' %>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="sg-5" style="background: #333;">
|
||||
</div>
|
||||
<div class="sg-5" style="background: #555;">
|
||||
</div>
|
||||
<div class="sg-5" style="background: #777;">
|
||||
</div>
|
||||
@ -19,7 +19,7 @@
|
||||
<div class="sgParent sg-12">
|
||||
|
||||
<div id="header" class="sg-11">
|
||||
<%= link_to image_tag('title.png'), '/' %>
|
||||
<%= link_to image_tag('title.png', :alt => 'Dan Barber Photography'), '/' %>
|
||||
</div>
|
||||
|
||||
<%= yield %>
|
||||
|
||||
1
app/views/notifier/contact_notification.text.erb
Normal file
1
app/views/notifier/contact_notification.text.erb
Normal file
@ -0,0 +1 @@
|
||||
<%=h @sender.message %>
|
||||
@ -7,10 +7,13 @@
|
||||
|
||||
<div class="sg-24 sgParent">
|
||||
|
||||
<div class="sg-11 about" style="background: white;">
|
||||
<div class="sg-11 about-content">
|
||||
<div>
|
||||
<%= raw(@content.html) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sg-11 about" style="background: url(/images/me.jpg);">
|
||||
<div class="sg-11" style="background: url(/images/me.jpg);">
|
||||
</div>
|
||||
|
||||
<div class="sg-5" style="background: #222;">
|
||||
@ -20,7 +23,7 @@
|
||||
<div class="sg-5" style="background: #555;">
|
||||
</div>
|
||||
<div class="sg-5 contact">
|
||||
<%= link_to raw('<span>contact</span>'), :action => 'contact' %>
|
||||
<%= link_to raw('<span>contact</span>'), new_contact_url %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@ -17,5 +17,5 @@
|
||||
<div class="sg-5" style="background: #555;">
|
||||
</div>
|
||||
<div class="sg-5 contact">
|
||||
<%= link_to raw('<span>contact</span>'), contact_url %>
|
||||
<%= link_to raw('<span>contact</span>'), new_contact_url %>
|
||||
</div>
|
||||
|
||||
@ -40,3 +40,5 @@ module Photos
|
||||
config.filter_parameters += [:password]
|
||||
end
|
||||
end
|
||||
|
||||
ActionMailer::Base.delivery_method = :sendmail
|
||||
18
config/initializers/typus_authentication.rb
Normal file
18
config/initializers/typus_authentication.rb
Normal file
@ -0,0 +1,18 @@
|
||||
Typus.setup do |config|
|
||||
|
||||
# Define authentication: +:none+, +:http_basic+, +:session+
|
||||
config.authentication = :session
|
||||
|
||||
# Define master_role.
|
||||
# config.master_role = "admin"
|
||||
|
||||
# Define relationship.
|
||||
# config.relationship = "typus_users"
|
||||
|
||||
# Define user_class_name.
|
||||
config.user_class_name = "AdminUser"
|
||||
|
||||
# Define user_fk.
|
||||
config.user_fk = "admin_user_id"
|
||||
|
||||
end
|
||||
@ -1,4 +1,6 @@
|
||||
Photos::Application.routes.draw do
|
||||
resources :contacts
|
||||
|
||||
# The priority is based upon order of creation:
|
||||
# first created -> highest priority.
|
||||
|
||||
@ -61,7 +63,8 @@ Photos::Application.routes.draw do
|
||||
root :to => 'pages#index'
|
||||
|
||||
match 'about' => 'pages#about', :as => :about
|
||||
match 'contact' => 'pages#contact', :as => :contact
|
||||
#match 'contact' => 'pages#contact', :as => :contact
|
||||
resources :contacts, :only => [:new, :create]
|
||||
|
||||
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
||||
# Note: This route will make all actions in every controller accessible via GET requests.
|
||||
|
||||
@ -22,3 +22,12 @@ Photo:
|
||||
search: title
|
||||
application: Photos
|
||||
|
||||
Page:
|
||||
fields:
|
||||
default: name, title
|
||||
form: name, title, content
|
||||
order_by:
|
||||
relationships:
|
||||
filters:
|
||||
search: title
|
||||
application: Photos
|
||||
@ -5,3 +5,4 @@
|
||||
admin:
|
||||
Category: create, read, update, delete
|
||||
Photo: create, read, update, delete
|
||||
Page: create, read, update, delete
|
||||
|
||||
17
config/typus/typus.yml
Normal file
17
config/typus/typus.yml
Normal file
@ -0,0 +1,17 @@
|
||||
# Typus Models Configuration File
|
||||
#
|
||||
# Use the README file as a reference to customize settings.
|
||||
|
||||
AdminUser:
|
||||
fields:
|
||||
default: first_name, last_name, role, email, language
|
||||
list: email, role, status
|
||||
form: first_name, last_name, role, email, password, password_confirmation, language
|
||||
options:
|
||||
selectors: role, language
|
||||
booleans:
|
||||
status: Active, Inactive
|
||||
filters: status, role
|
||||
search: first_name, last_name, email, role
|
||||
application: Admin Panel
|
||||
description: Users Administration
|
||||
6
config/typus/typus_roles.yml
Normal file
6
config/typus/typus_roles.yml
Normal file
@ -0,0 +1,6 @@
|
||||
# Typus Roles Configuration File
|
||||
#
|
||||
# Use the README file as a reference to customize settings.
|
||||
|
||||
admin:
|
||||
AdminUser: all
|
||||
Binary file not shown.
22
db/migrate/20101011133558_create_admin_users.rb
Normal file
22
db/migrate/20101011133558_create_admin_users.rb
Normal file
@ -0,0 +1,22 @@
|
||||
class CreateAdminUsers < ActiveRecord::Migration
|
||||
|
||||
def self.up
|
||||
create_table :admin_users do |t|
|
||||
t.string :first_name, :default => "", :null => false
|
||||
t.string :last_name, :default => "", :null => false
|
||||
t.string :role, :null => false
|
||||
t.string :email, :null => false
|
||||
t.boolean :status, :default => false
|
||||
t.string :token, :null => false
|
||||
t.string :salt, :null => false
|
||||
t.string :crypted_password, :null => false
|
||||
t.string :preferences
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :admin_users
|
||||
end
|
||||
|
||||
end
|
||||
15
db/migrate/20101012132954_create_pages.rb
Normal file
15
db/migrate/20101012132954_create_pages.rb
Normal file
@ -0,0 +1,15 @@
|
||||
class CreatePages < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :pages do |t|
|
||||
t.string :name
|
||||
t.string :title
|
||||
t.text :content
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :pages
|
||||
end
|
||||
end
|
||||
24
db/schema.rb
24
db/schema.rb
@ -10,7 +10,21 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20101008172319) do
|
||||
ActiveRecord::Schema.define(:version => 20101012132954) do
|
||||
|
||||
create_table "admin_users", :force => true do |t|
|
||||
t.string "first_name", :default => "", :null => false
|
||||
t.string "last_name", :default => "", :null => false
|
||||
t.string "role", :null => false
|
||||
t.string "email", :null => false
|
||||
t.boolean "status", :default => false
|
||||
t.string "token", :null => false
|
||||
t.string "salt", :null => false
|
||||
t.string "crypted_password", :null => false
|
||||
t.string "preferences"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "categories", :force => true do |t|
|
||||
t.string "name"
|
||||
@ -27,6 +41,14 @@ ActiveRecord::Schema.define(:version => 20101008172319) do
|
||||
t.integer "photo_id"
|
||||
end
|
||||
|
||||
create_table "pages", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "title"
|
||||
t.text "content"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "photos", :force => true do |t|
|
||||
t.string "flickr_url"
|
||||
t.string "photo_file_name"
|
||||
|
||||
4872
log/development.log
4872
log/development.log
File diff suppressed because it is too large
Load Diff
BIN
public/.DS_Store
vendored
BIN
public/.DS_Store
vendored
Binary file not shown.
@ -8,6 +8,13 @@ body {
|
||||
a {
|
||||
text-decoration: none;
|
||||
}
|
||||
p a {
|
||||
display: inline !important;
|
||||
color: #acf;
|
||||
}
|
||||
p a:hover {
|
||||
color: #fff;
|
||||
}
|
||||
#page {
|
||||
position: absolute;
|
||||
top: 40%;
|
||||
@ -37,7 +44,7 @@ a {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
position: absolute;
|
||||
bottom: 15px;
|
||||
bottom: 18px;
|
||||
right: 20px;
|
||||
}
|
||||
#footer {
|
||||
@ -173,3 +180,83 @@ img {
|
||||
.prev-link:hover, .next-link:hover {
|
||||
background: rgba(255,255,255,0.2);
|
||||
}
|
||||
.about-content {
|
||||
background: #444;
|
||||
color: #ccc;
|
||||
}
|
||||
.about-content div {
|
||||
padding: 15px 20px;
|
||||
}
|
||||
.about-content div p {
|
||||
margin-bottom: 0.6em;
|
||||
line-height: 1.4em;
|
||||
}
|
||||
/* FORM */
|
||||
.contact-form {
|
||||
background: #ddd;
|
||||
}
|
||||
.field_with_errors {
|
||||
display: inline;
|
||||
}
|
||||
form {
|
||||
padding: 10px 20px;
|
||||
}
|
||||
form p {
|
||||
margin: 10px 0;
|
||||
}
|
||||
form p {
|
||||
color: #555;
|
||||
}
|
||||
form label {
|
||||
color: #666;
|
||||
display: block;
|
||||
width: 100px;
|
||||
float: left;
|
||||
}
|
||||
form textarea {
|
||||
height: 150px;
|
||||
width: 315px;
|
||||
}
|
||||
form textarea, form input[type='text'] {
|
||||
font-family:"Helvetica Neue","Arial","Helvatica",sans-serif;
|
||||
font-size:14px;
|
||||
padding: 3px;
|
||||
color: #333;
|
||||
border: 2px solid #999;
|
||||
-moz-border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
#alert {
|
||||
background: #fffeef;
|
||||
color: #664400;
|
||||
border-width: 2px 0;
|
||||
border-style: solid;
|
||||
border-color: #996600;
|
||||
padding: 0 10px 2px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
#notice {
|
||||
background: #efffef;
|
||||
color: #446600;
|
||||
border-width: 2px 0;
|
||||
border-style: solid;
|
||||
border-color: #669900;
|
||||
padding: 0 10px 2px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
.field_with_errors input, .field_with_errors textarea {
|
||||
background: #ffefef;
|
||||
border-color: #cc3333 !important;
|
||||
}
|
||||
form input[type='submit'] {
|
||||
background: #666;
|
||||
font-family:"Helvetica Neue","Arial","Helvatica",sans-serif;
|
||||
font-size:14px;
|
||||
padding: 3px;
|
||||
color: white;
|
||||
border: 2px solid #333;
|
||||
-moz-border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
@ -14,7 +14,7 @@ table {border-collapse:collapse; border-spacing:0;} /* tables still need 'cellsp
|
||||
body {background-color:#f4f4f4; font-size:62.5%; line-height:28px; /* for RTL add: 'direction: rtl;' */ }
|
||||
|
||||
/* your main wrapping div */
|
||||
#wrapper{ margin: 0 auto; position:relative; overflow: hidden; width: 994px;background:#fff url(../images/sg_grid_sub.png) center top repeat; }
|
||||
#wrapper{ margin: 0 auto; position:relative; overflow: hidden; width: 994px;background:#fff; }
|
||||
#container{width:1008px; /* essential */ margin-left:-7px;}
|
||||
|
||||
/* global styling to apply to all columns */
|
||||
|
||||
11
test/fixtures/contacts.yml
vendored
Normal file
11
test/fixtures/contacts.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
# This model initially had no columns defined. If you add columns to the
|
||||
# model remove the '{}' from the fixture names and add the columns immediately
|
||||
# below each fixture, per the syntax in the comments below
|
||||
#
|
||||
one: {}
|
||||
# column: value
|
||||
#
|
||||
two: {}
|
||||
# column: value
|
||||
11
test/fixtures/pages.yml
vendored
Normal file
11
test/fixtures/pages.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
# This model initially had no columns defined. If you add columns to the
|
||||
# model remove the '{}' from the fixture names and add the columns immediately
|
||||
# below each fixture, per the syntax in the comments below
|
||||
#
|
||||
one: {}
|
||||
# column: value
|
||||
#
|
||||
two: {}
|
||||
# column: value
|
||||
10
test/functional/admin/admin_users_controller_test.rb
Normal file
10
test/functional/admin/admin_users_controller_test.rb
Normal file
@ -0,0 +1,10 @@
|
||||
require 'test_helper'
|
||||
|
||||
class Admin::AdminUsersControllerTest < ActionController::TestCase
|
||||
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
|
||||
end
|
||||
10
test/functional/admin/pages_controller_test.rb
Normal file
10
test/functional/admin/pages_controller_test.rb
Normal file
@ -0,0 +1,10 @@
|
||||
require 'test_helper'
|
||||
|
||||
class Admin::PagesControllerTest < ActionController::TestCase
|
||||
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
|
||||
end
|
||||
8
test/functional/contacts_controller_test.rb
Normal file
8
test/functional/contacts_controller_test.rb
Normal file
@ -0,0 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ContactsControllerTest < ActionController::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
8
test/functional/notifier_test.rb
Normal file
8
test/functional/notifier_test.rb
Normal file
@ -0,0 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class NotifierTest < ActionMailer::TestCase
|
||||
# replace this with your real tests
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
8
test/unit/contact_test.rb
Normal file
8
test/unit/contact_test.rb
Normal file
@ -0,0 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ContactTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
4
test/unit/helpers/contacts_helper_test.rb
Normal file
4
test/unit/helpers/contacts_helper_test.rb
Normal file
@ -0,0 +1,4 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ContactsHelperTest < ActionView::TestCase
|
||||
end
|
||||
8
test/unit/page_test.rb
Normal file
8
test/unit/page_test.rb
Normal file
@ -0,0 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PageTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user