Skip to content
Browse files

Removed assets and added new ones plus apt of features

Blogs, Comments and a vast amount of work on authentication,
authorisation, cancan 2.0 and sorcery, and cleaning up my mess to get
it working
  • Loading branch information...
1 parent aa8bbe1 commit 6d05d59aac5727e98721035b5c26fbdeb0f415fb @safarista committed
Showing with 1,287 additions and 696 deletions.
  1. +1 −1 Gemfile
  2. +8 −2 Gemfile.lock
  3. +3 −0 app/assets/javascripts/comments.js.coffee
  4. +3 −0 app/assets/javascripts/posts.js.coffee
  5. +30 −4 app/assets/stylesheets/bootstrap_and_overrides.css.less
  6. +3 −0 app/assets/stylesheets/posts.css.scss
  7. +4 −1 app/controllers/application_controller.rb
  8. +102 −0 app/controllers/comments_controller.rb
  9. +0 −1 app/controllers/destinations_controller.rb
  10. +1 −2 app/controllers/home_controller.rb
  11. +92 −0 app/controllers/posts_controller.rb
  12. +11 −0 app/controllers/safaris_controller.rb
  13. +1 −1 app/controllers/sessions_controller.rb
  14. +8 −1 app/controllers/welcome_controller.rb
  15. +2 −0 app/helpers/comments_helper.rb
  16. +2 −0 app/helpers/posts_helper.rb
  17. +17 −18 app/models/ability.rb
  18. +8 −0 app/models/album.rb
  19. +10 −0 app/models/beach.rb
  20. +7 −0 app/models/comment.rb
  21. +9 −0 app/models/day_trip.rb
  22. +9 −0 app/models/destination.rb
  23. +11 −0 app/models/photo.rb
  24. +25 −0 app/models/post.rb
  25. +10 −0 app/models/safari.rb
  26. +11 −0 app/models/trek.rb
  27. +16 −9 app/models/user.rb
  28. +2 −0 app/views/albums/index.html.erb
  29. +16 −14 app/views/albums/show.html.erb
  30. +6 −3 app/views/beaches/index.html.erb
  31. +47 −40 app/views/beaches/show.html.erb
  32. +44 −0 app/views/comments/_form.html.erb
  33. +3 −0 app/views/comments/edit.html.erb
  34. +36 −0 app/views/comments/index.html.erb
  35. +4 −0 app/views/comments/new.html.erb
  36. +25 −0 app/views/comments/show.html.erb
  37. +6 −3 app/views/day_trips/index.html.erb
  38. +46 −37 app/views/day_trips/show.html.erb
  39. +74 −1 app/views/home/index.html.erb
  40. +5 −0 app/views/layouts/_footer.html.erb
  41. +35 −19 app/views/layouts/_header.html.erb
  42. +12 −13 app/views/layouts/application.html.erb
  43. +6 −3 app/views/photos/index.html.erb
  44. +13 −10 app/views/photos/show.html.erb
  45. +47 −0 app/views/posts/_form.html.erb
  46. +4 −0 app/views/posts/edit.html.erb
  47. +21 −0 app/views/posts/index.html.erb
  48. +4 −0 app/views/posts/new.html.erb
  49. +106 −0 app/views/posts/show.html.erb
  50. +6 −3 app/views/safaris/index.html.erb
  51. +47 −38 app/views/safaris/show.html.erb
  52. +19 −0 app/views/sessions/new.html.erb
  53. +6 −4 app/views/treks/index.html.erb
  54. +48 −38 app/views/treks/show.html.erb
  55. +33 −14 app/views/users/_form.html.erb
  56. +7 −3 app/views/users/index.html.erb
  57. +15 −27 app/views/users/show.html.erb
  58. +6 −1 config/routes.rb
  59. +1 −1 db/migrate/20120525134514_sorcery_core.rb
  60. +14 −0 db/migrate/20120526105427_create_posts.rb
  61. +18 −0 db/migrate/20120526112714_add_slug_and_index_to_safaris.rb
  62. +18 −0 db/migrate/20120526115216_create_friendly_id_slugs.rb
  63. +18 −0 db/migrate/20120526225413_create_comments.rb
  64. +53 −2 db/schema.rb
  65. +1 −1 ...pplication-e8c6a40e993ef6eb6203621f6d3c3c58.js → application-4c366c2cf1e575e9339376f8afa673e0.js}
  66. BIN public/assets/{application.js.gz → application-4c366c2cf1e575e9339376f8afa673e0.js.gz}
  67. +1 −1 ...lication-b6e11ac4d2aa1a1d20f0a17990d75070.css → application-929f265990534495556f2ff82fbac689.css}
  68. BIN ...on-b6e11ac4d2aa1a1d20f0a17990d75070.css.gz → application-929f265990534495556f2ff82fbac689.css.gz}
  69. BIN public/assets/application-e8c6a40e993ef6eb6203621f6d3c3c58.js.gz
  70. +0 −1 public/assets/application.css
  71. BIN public/assets/application.css.gz
  72. +0 −19 public/assets/application.js
  73. +0 −175 public/assets/fontawesome-webfont-8276485587c7ff2e54d7422809134349.svg
  74. BIN public/assets/fontawesome-webfont-a01aacd973fb4d032729f9c498683caa.ttf
  75. BIN public/assets/fontawesome-webfont-b6a0f80a39a7f60a250fad1e8e2ecf8b.woff
  76. BIN public/assets/fontawesome-webfont-d5b0cb5aed6480abcf670ba04f391ad3.svgz
  77. BIN public/assets/fontawesome-webfont-eeecec082197cc0255b0c549b4e612ea.eot
  78. BIN public/assets/fontawesome-webfont.eot
  79. +0 −175 public/assets/fontawesome-webfont.svg
  80. BIN public/assets/fontawesome-webfont.svgz
  81. BIN public/assets/fontawesome-webfont.ttf
  82. BIN public/assets/fontawesome-webfont.woff
  83. +0 −10 public/assets/manifest.yml
  84. BIN public/assets/twitter/bootstrap/glyphicons-halflings-2ed0cba6eca0f44737ab78f1e58bc11e.png
  85. BIN public/assets/twitter/bootstrap/glyphicons-halflings-white-4fbb6a0b9b4e61912f486ac494a858f1.png
  86. BIN public/assets/twitter/bootstrap/glyphicons-halflings-white.png
  87. BIN public/assets/twitter/bootstrap/glyphicons-halflings.png
  88. +10 −0 test/unit/ability_test.rb
View
2 Gemfile
@@ -44,7 +44,7 @@ gem 'bcrypt-ruby', '~> 3.0.0'
# Authentication and Authorisation
gem 'sorcery'
-gem 'cancan'
+gem "cancan", git: "git://github.com/ryanb/cancan.git", branch: "2.0"
# SEO and text formatting
gem 'friendly_id'
View
10 Gemfile.lock
@@ -1,4 +1,11 @@
GIT
+ remote: git://github.com/ryanb/cancan.git
+ revision: ccd24ab30fdd0b48ac0ad71080445f5366788208
+ branch: 2.0
+ specs:
+ cancan (2.0.0.alpha)
+
+GIT
remote: git://github.com/seyhunak/twitter-bootstrap-rails.git
revision: eb348d89373bd3828848887bc0f7c3a6aed236d9
specs:
@@ -41,7 +48,6 @@ GEM
arel (3.0.2)
bcrypt-ruby (3.0.1)
builder (3.0.0)
- cancan (1.6.7)
carrierwave (0.6.2)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
@@ -174,7 +180,7 @@ PLATFORMS
DEPENDENCIES
bcrypt-ruby (~> 3.0.0)
- cancan
+ cancan!
carrierwave
coffee-rails (~> 3.2.1)
fog
View
3 app/assets/javascripts/comments.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3 app/assets/javascripts/posts.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
34 app/assets/stylesheets/bootstrap_and_overrides.css.less
@@ -114,13 +114,39 @@ color: #999;
font-weight: 300;
}
+// @media (max-width: 1015px) amd (min-width: 980px){
+// .jumbotron h1{
+// font-size: 42px;
+// }
+// .jumbotron p {
+// margin-right: 0;
+// margin-left: 0;
+// font-size:18px;
+// line-height:24px;
+// }
+// .jumbotron .btn {
+// margin-bottom: 10px;
+// font-size: 18px;
+// padding: 10px 14px;
+// margin: 0 auto 10px;
+// }
+// }
@media (max-width: 980px) and (min-width: 768px) {
.jumbotron h1{
- font-size: 62px;
+ font-size: 52px;
+ }
+ .jumbotron p {
+ margin-right: 0;
+ margin-left: 0;
+ font-size:18px;
+ line-height:24px;
}
.jumbotron .btn {
margin-bottom: 10px;
+ font-size: 18px;
+ padding: 10px 14px;
+ margin: 0 auto 10px;
}
}
@@ -141,18 +167,18 @@ color: #999;
@media (max-width: 480px){
.jumbotron h1{
- font-size: 45px;
+ font-size: 35px;
margin-right: 0;
}
.jumbotron p{
margin-right:0;
margin-left:0;
- font-size:18px;
+ font-size:16px;
line-height:24px;
}
.jumbotron .btn {
display: block;
- font-size: 18px;
+ font-size: 16px;
padding: 10px 14px;
margin: 0 auto 10px;
}
View
3 app/assets/stylesheets/posts.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the posts controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
5 app/controllers/application_controller.rb
@@ -1,10 +1,13 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+
before_filter :require_login
- load_and_authorize_resource
+ enable_authorization
+
protected
def not_authenticated
redirect_to root_path, :alert => "Please login first."
end
+
end
View
102 app/controllers/comments_controller.rb
@@ -0,0 +1,102 @@
+class CommentsController < ApplicationController
+ skip_before_filter :require_login
+ # load_and_authorize_resource :post
+ # load_and_authorize_resource :comments, :through => :post
+ #
+ # skip_load_and_authorize_resource :only => :show
+ # skip_load_and_authorize_resource :post, :only => :show
+
+ # GET /comments
+ # GET /comments.json
+ def index
+ @post = Post.try(:find, params[:post_id])
+ @comments = @post.comments
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @comments }
+ end
+ end
+
+ # GET /comments/1
+ # GET /comments/1.json
+ def show
+ @post = Post.try(:find, params[:post_id])
+ @comment = @post.comments.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @comment }
+ end
+ end
+
+ # GET /comments/new
+ # GET /comments/new.json
+ def new
+ @post = Post.try(:find, params[:post_id])
+ @comment = @post.comments.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @comment }
+ end
+ end
+
+ # GET /comments/1/edit
+ def edit
+ @post = Post.try(:find, params[:post_id])
+ @comment = @post.comments.find(params[:id])
+ end
+
+ # POST /comments
+ # POST /comments.json
+ def create
+ @post = Post.try(:find, params[:post_id])
+ @comment = @post.comments.create!(params[:comment])
+ @comment.ip_address_info = request.remote_ip
+
+ if logged_in?
+ @comment.commenter = current_user.full_name
+ @comment.comment_email = current_user.email
+ end
+
+ respond_to do |format|
+ if @comment.save
+ format.html { redirect_to @post, notice: 'Comment was successfully created.' }
+ format.json { render json: @comment, status: :created, location: @comment }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @comment.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /comments/1
+ # PUT /comments/1.json
+ def update
+ @post = Post.try(:find, params[:post_id])
+ @comment = @post.comments.find(params[:id])
+
+ respond_to do |format|
+ if @comment.update_attributes(params[:comment])
+ format.html { redirect_to @post, notice: 'Comment was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @comment.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /comments/1
+ # DELETE /comments/1.json
+ def destroy
+ @comment = Comment.find(params[:id])
+ @comment.destroy
+
+ respond_to do |format|
+ format.html { redirect_to comments_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
1 app/controllers/destinations_controller.rb
@@ -1,5 +1,4 @@
class DestinationsController < ApplicationController
- skip_load_and_authorize_resource :only => [:index, :show]
before_filter :find_destineable
respond_to :html
# GET /destinations
View
3 app/controllers/home_controller.rb
@@ -1,8 +1,7 @@
class HomeController < ApplicationController
skip_before_filter :require_login
- skip_load_and_authorize_resource :only => :index
def index
@title = 'Welcome to Bless Africa Safaris and Tours Tanzania'
- @album = Album.try(:first)
+ @album = Album.try(:find, 2)
end
end
View
92 app/controllers/posts_controller.rb
@@ -0,0 +1,92 @@
+class PostsController < ApplicationController
+ skip_before_filter :require_login
+ # GET /posts
+ # GET /posts.json
+ def index
+ if can? :access, :posts
+ @posts = Post.order("posts.published DESC")
+ else
+ @posts = Post.where("posts.published IS NOT NULL" ).order("posts.published DESC")
+ end
+
+ respond_to do |format|
+ format.html # index.html.erb
+ end
+ end
+
+ # GET /posts/1
+ # GET /posts/1.json
+ def show
+ @post = Post.find(params[:id])
+ @comments = @post.comments
+ @comment = Comment.new
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @post }
+ end
+ end
+
+ # GET /posts/new
+ # GET /posts/new.json
+ def new
+ @post = Post.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @post }
+ end
+ end
+
+ # GET /posts/1/edit
+ def edit
+ @post = Post.try(:find, params[:id])
+ end
+
+ # POST /posts
+ # POST /posts.json
+ def create
+ @post = current_user.posts.new(params[:post])
+ @post.ip_address_info = request.remote_ip
+ @post.published = Time.now unless !params[:post][:published] == '1'
+ respond_to do |format|
+ if @post.save
+ format.html { redirect_to @post, notice: 'Post was successfully created.' }
+ format.json { render json: @post, status: :created, location: @post }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @post.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /posts/1
+ # PUT /posts/1.json
+ def update
+ @post = Post.try(:find, params[:id])
+ @post.published = Time.now # if !params[:post][:published].blank?
+
+
+ respond_to do |format|
+ if @post.update_attributes(params[:post])
+ format.html { redirect_to @post, notice: 'Post was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @post.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /posts/1
+ # DELETE /posts/1.json
+ def destroy
+ @post = Post.find(params[:id])
+ @post.destroy
+
+ respond_to do |format|
+ format.html { redirect_to posts_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
11 app/controllers/safaris_controller.rb
@@ -1,5 +1,11 @@
class SafarisController < ApplicationController
+ # # Filters and Authorization
skip_before_filter :require_login, :only => [:index, :show]
+
+ # load_and_authorize_resource :safari # no customization needed here
+ # load_and_authorize_resource :destination, :through => :safari
+ # before_filter :authorize_parent
+
# GET /safaris
# GET /safaris.json
def index
@@ -81,4 +87,9 @@ def destroy
format.json { head :no_content }
end
end
+
+ private
+ # def authorize_parent
+ # authorize! :read, @safari
+ # end
end
View
2 app/controllers/sessions_controller.rb
@@ -19,6 +19,6 @@ def create
def destroy
logout
- redirect_to(:users, :notice => 'Logged out!')
+ redirect_to(:root, :notice => 'Logged out!')
end
end
View
9 app/controllers/welcome_controller.rb
@@ -1,37 +1,44 @@
class WelcomeController < ApplicationController
+ load_and_authorize_resource :class => false
skip_before_filter :require_login
- skip_load_and_authorize_resource
def about_us
+ # authorize! :static_page, :about_us
@title = 'About Bless Africa Safaris and Tours'
end
def accommodation
+ # authorize! :static_page, :accommodation
@title = 'Accommodation providers in Moshi, Arusha, Kilimanjaro and beach resorts'
end
def contact_us
+ # authorize! :static_page, :contact_us
@title = 'Contact Us'
end
def itineraries
+ # authorize! :static_page, :itineraries
@trip_types = [Beach, Safari, Trek, DayTrip]
@title = 'Safari, Trekking, Beach and Short day trip itineraries'
end
def important_information
+ # authorize! :static_page, :important_information
@title = 'Important information for your safari and comfort'
end
def about_tanzania
+ # authorize! :static_page, :about_tanzania
@title = 'About Tanzania, Mt Kilimanjaro and Trekking, Safaris, Beaches and short day trips'
end
def kit_hire
+ # authorize! :static_page, :kit_hire
@title = "Trekking and camping Kit hire and providers"
end
end
View
2 app/helpers/comments_helper.rb
@@ -0,0 +1,2 @@
+module CommentsHelper
+end
View
2 app/helpers/posts_helper.rb
@@ -0,0 +1,2 @@
+module PostsHelper
+end
View
35 app/models/ability.rb
@@ -2,28 +2,27 @@ class Ability
include CanCan::Ability
def initialize(user)
- # Define abilities for the passed in user here. For example:
- #
- user ||= User.new # guest user (not logged in)
+ # Define abilities for the passed in (current) user. For example:
+ user ||= User.new
if user.admin?
- can :manage, :all
+ can :access, :all
else
- can :read, :all
- can [:create], User
- can [:update, :destroy], User, :id => user.id
+ can :read, [:home, :albums, :photos, :treks, :beaches, :safaris, :day_trips, :posts, :comments]
+ can :create, [:comments, :users, :sessions]
+ can :destroy, :sessions
+ can :read, :users
+ can [:update, :destroy], :users, :id => user.id
+ can :read, :destinations
+ can :access, :welcome
end
-
- # The first argument to `can` is the action you are giving the user permission to do.
- # If you pass :manage it will apply to every action. Other common actions here are
- # :read, :create, :update and :destroy.
- #
- # The second argument is the resource the user can perform the action on. If you pass
- # :all it will apply to every resource. Otherwise pass a Ruby class of the resource.
- #
- # The third argument is an optional hash of conditions to further filter the objects.
- # For example, here the user can only update published articles.
+
+ # Here if there is a user he will be able to perform any action on any controller.
+ # If someone is not logged in he can only access the home, users, and sessions controllers.
#
- # can :update, Article, :published => true
+ # The first argument to `can` is the action the user can perform. The second argument
+ # is the controller name they can perform that action on. You can pass :access and :all
+ # to represent any action and controller respectively. Passing an array to either of
+ # these will grant permission on each item in the array.
#
# See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities
end
View
8 app/models/album.rb
@@ -1,4 +1,12 @@
class Album < ActiveRecord::Base
+ # MassAssignment protection
attr_accessible :description, :title
+
+ # Associations
has_many :photos, dependent: :delete_all
+
+ # # SEO search friendly URLS with FriendlyId
+ extend FriendlyId
+ friendly_id :title, use: :history
+
end
View
10 app/models/beach.rb
@@ -1,5 +1,15 @@
class Beach < ActiveRecord::Base
+ # MassAssignment protection
attr_accessible :description, :title
+
+ # Validations
has_many :destinations, as: :destineable, dependent: :delete_all
+
+ # Form and Resource Nesting
accepts_nested_attributes_for :destinations, allow_destroy: true, reject_if: :all_blank
+
+ # # SEO search friendly URLS with FriendlyId
+ extend FriendlyId
+ friendly_id :title, use: :history
+
end
View
7 app/models/comment.rb
@@ -0,0 +1,7 @@
+class Comment < ActiveRecord::Base
+ belongs_to :post
+ attr_accessible :comment_email, :commenter, :content, :ip_address_info, :comment_url
+
+ # Validations
+ validates :comment_email, :commenter, :content, presence: true
+end
View
9 app/models/day_trip.rb
@@ -1,5 +1,14 @@
class DayTrip < ActiveRecord::Base
+ # MassAssignment protection
attr_accessible :description, :title
+
+ # Assoxiations
has_many :destinations, as: :destineable, dependent: :delete_all
+
+ # Nesting resources and forms
accepts_nested_attributes_for :destinations, allow_destroy: true, reject_if: :all_blank
+
+ # # SEO search friendly URLS with FriendlyId
+ extend FriendlyId
+ friendly_id :title, use: :history
end
View
9 app/models/destination.rb
@@ -1,4 +1,13 @@
class Destination < ActiveRecord::Base
+
+ # MassAssignment protection
attr_accessible :description, :destineable_id, :destineable_type, :title, :price
+
+ # Associations
belongs_to :destineable, polymorphic: true
+
+ # # SEO search friendly URLS with FriendlyId
+ # extend FriendlyId
+ # friendly_id :title, use: :history
+
end
View
11 app/models/photo.rb
@@ -1,7 +1,18 @@
class Photo < ActiveRecord::Base
+ # Mounted image uploader
mount_uploader :name, MediaUploader
+
+ # MassAssignment protectio
attr_accessible :caption, :name
+
+ # Validations
validates :name, presence: true
+
+ # Associations
belongs_to :album
+ # # # SEO search friendly URLS with FriendlyId
+ # extend FriendlyId
+ # friendly_id :name, use: :history
+
end
View
25 app/models/post.rb
@@ -0,0 +1,25 @@
+class Post < ActiveRecord::Base
+ # # ====SCHEMA structure ======
+ # t.string :title
+ # t.string :slag
+ # t.string :ip_address_info
+ # t.datetime :published
+ # t.boolean :ban_comments
+ # t.text :content
+
+ # # MassAssignment protection
+ attr_accessible :ban_comments, :content, :ip_address_info, :published, :slug, :title, :comments_attributes
+
+ # # Validations
+ validates :title, :content, presence: true
+
+ # # Associations
+ has_many :comments, dependent: :delete_all
+ belongs_to :user
+
+ # # SEO search friendly URLS with FriendlyId
+ extend FriendlyId
+ friendly_id :title, use: :history
+ accepts_nested_attributes_for :comments, :allow_destroy => true, :reject_if => proc { |obj| obj.blank? }
+
+end
View
10 app/models/safari.rb
@@ -1,6 +1,16 @@
class Safari < ActiveRecord::Base
+
+ # MassAssignment protection
attr_accessible :description, :price, :title
+
+ # Associations
has_many :destinations, as: :destineable, dependent: :delete_all
+
+ # NestingForms
accepts_nested_attributes_for :destinations, allow_destroy: true, reject_if: :all_blank
+ # # SEO search friendly URLS with FriendlyId
+ extend FriendlyId
+ friendly_id :title, use: :history
+
end
View
11 app/models/trek.rb
@@ -1,5 +1,16 @@
class Trek < ActiveRecord::Base
+
+ # MassAssignemnt protection
attr_accessible :description, :title
+
+ # Associations
has_many :destinations, as: :destineable, dependent: :delete_all
+
+ # NestingForms and Resources
accepts_nested_attributes_for :destinations, allow_destroy: true, reject_if: :all_blank
+
+ # # SEO search friendly URLS with FriendlyId
+ extend FriendlyId
+ friendly_id :title, use: :history
+
end
View
25 app/models/user.rb
@@ -1,7 +1,7 @@
class User < ActiveRecord::Base
- # ========SCHEMA layout========
- # t.string :full_name, :null => false
+ # #========SCHEMA Structure========
+ # t.string :full_name, :null => false
# t.string :slag
# t.string :username, :null => false
# t.string :email, :default => nil
@@ -12,22 +12,29 @@ class User < ActiveRecord::Base
# t.string :crypted_password, :default => nil
# t.string :salt, :default => nil
- # Athentication
+ # # Athentication
authenticates_with_sorcery!
- # MassAssignment protection
- attr_accessible :full_name, :username, :email, :admin, :moderator, :ip_address_info, :password, :password_confirmation, :about, :slag
+ # # MassAssignment protection
+ attr_accessible :full_name, :username, :email, :admin, :moderator, :ip_address_info, :password, :password_confirmation, :about, :slug
- # Validations
+ # # Validations
validates :full_name, :username, presence: true
validates :username, length: { in: 8..15 }
validates :email, presence: true,
- uniqueness: true,
+ uniqueness: { :case_sensitive => false },
format: { with: /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i,
message: 'Email format is not acceptable.' }
- validates :password, length: { in: 8..15 }
+ validates :password, length: { in: 8..15 }, if: :password
validates :password, confirmation: true
- validates :password_confirmation, presence: true
+ validates :password_confirmation, presence: true, if: :password
+
+ # # Associations
+ has_many :posts, dependent: :nullify
+
+ # # SEO search friendly URLS with FriendlyId
+ extend FriendlyId
+ friendly_id :full_name, use: :history
end
View
2 app/views/albums/index.html.erb
@@ -16,6 +16,8 @@
</ul>
<hr>
+<% if can? :access, @albums %>
<%= link_to t('.new', :default => t("helpers.links.new_album")),
new_album_path,
:class => 'btn btn-primary' %>
+<% end %>
View
30 app/views/albums/show.html.erb
@@ -10,17 +10,19 @@
<%= @album.description %>
</p>
-<div class="form-actions">
- <%= link_to t('.back', :default => t("helpers.links.back")),
- albums_path, :class => 'btn' %>
- <%= link_to t('.edit', :default => t("helpers.links.edit")),
- edit_album_path(@album), :class => 'btn' %>
- <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
- album_path(@album),
- :method => 'delete',
- :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
- :class => 'btn btn-danger' %>
- <%= link_to t('.new', :default => t("helpers.links.add_new_photos")),
- new_album_photo_path(@album),
- :class => 'btn btn-primary' %>
-</div>
+<% if can? :access, @album %>
+ <div class="form-actions">
+ <%= link_to t('.back', :default => t("helpers.links.back")),
+ albums_path, :class => 'btn' %>
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
+ edit_album_path(@album), :class => 'btn' %>
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
+ album_path(@album),
+ :method => 'delete',
+ :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
+ :class => 'btn btn-danger' %>
+ <%= link_to t('.new', :default => t("helpers.links.add_new_photos")),
+ new_album_photo_path(@album),
+ :class => 'btn btn-primary' %>
+ </div>
+<% end %>
View
9 app/views/beaches/index.html.erb
@@ -11,6 +11,9 @@
<hr>
<% end %>
-<%= link_to t('.new', :default => t("helpers.links.add_another_beach")),
- new_beach_path,
- :class => 'btn btn-primary' %>
+
+<% if can? :access, @beaches %>
+ <%= link_to t('.new', :default => t("helpers.links.add_another_beach")),
+ new_beach_path,
+ :class => 'btn btn-primary' %>
+<% end %>
View
87 app/views/beaches/show.html.erb
@@ -2,19 +2,21 @@
<h1><%=t '.title', :default => @beach.title %></h1>
<%= markdown @beach.description %>
-
-<div class="form-actions">
- <%= link_to t('.back', :default => t("helpers.links.back")),
- beaches_path, :class => 'btn' %>
- <%= link_to t('.edit', :default => t("helpers.links.edit")),
- edit_beach_path(@beach), :class => 'btn' %>
- <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
- beach_path(@beach),
- :method => 'delete',
- :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
- :class => 'btn btn-danger' %>
-</div>
-
+
+<% if can? :access, @beach %>
+ <div class="form-actions">
+ <%= link_to t('.back', :default => t("helpers.links.back")),
+ beaches_path, :class => 'btn' %>
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
+ edit_beach_path(@beach), :class => 'btn' %>
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
+ beach_path(@beach),
+ :method => 'delete',
+ :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
+ :class => 'btn btn-danger' %>
+ </div>
+<% end %>
+<br>
<article class="">
<% if !@beach.destinations.blank? %>
@@ -23,7 +25,7 @@
<% for bc in @beach.destinations %>
<h3><%= link_to bc.title, beach_destination_path(@beach, bc), title: bc.title %></h3>
<%= markdown bc.description.truncate(300) %>
- <p><%= link_to 'Read more...', beach_destination_path(@beach, bc) %></p>
+ <p><%= link_to 'Read more...', beach_destination_path(@beach, bc), class: 'btn' %></p>
<% end %>
<% else %>
<div class="alert">
@@ -33,31 +35,36 @@
<% end %>
</article>
<hr>
-<%= form_for [@beach, @beach.destinations.new], :html => { :class => 'form-horizontal' } do |f| %>
- <h3 class="page-title">Add a new itinerary</h3>
- <br>
- <div class="control-group">
- <%= f.label :title, 'Destination name', :class => 'control-label' %>
- <div class="controls">
- <%= f.text_field :title, :class => 'span3', required: true %>
- </div>
- </div>
- <div class="control-group">
- <%= f.label :price, 'Price breakdown', :class => 'control-label' %>
- <div class="controls">
- <%= f.text_area :price, :class => 'span6', rows: 6 %>
- </div>
- </div>
- <div class="control-group">
- <%= f.label :description, class: 'control-label' %>
- <div class="controls">
- <%= f.text_area :description, class: 'span6', rows: 8 %>
- </div>
- </div>
- <div class="form-actions">
- <%= f.submit nil, :class => 'btn btn-primary' %>
- <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
- beaches_path, :class => 'btn' %>
- </div>
+
+<% if can? :access, @beach %>
+
+ <%= form_for [@beach, @beach.destinations.new], :html => { :class => 'form-horizontal' } do |f| %>
+ <h3 class="page-title">Add a new itinerary</h3>
+ <br>
+ <div class="control-group">
+ <%= f.label :title, 'Destination name', :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :title, :class => 'span3', required: true %>
+ </div>
+ </div>
+ <div class="control-group">
+ <%= f.label :price, 'Price breakdown', :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_area :price, :class => 'span6', rows: 6 %>
+ </div>
+ </div>
+ <div class="control-group">
+ <%= f.label :description, class: 'control-label' %>
+ <div class="controls">
+ <%= f.text_area :description, class: 'span6', rows: 8 %>
+ </div>
+ </div>
+
+ <div class="form-actions">
+ <%= f.submit nil, :class => 'btn btn-primary' %>
+ <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
+ beaches_path, :class => 'btn' %>
+ </div>
+ <% end %>
<% end %>
View
44 app/views/comments/_form.html.erb
@@ -0,0 +1,44 @@
+<%= form_for [@post, @comment], :html => { :class => 'form-horizontal' } do |f| %>
+
+ <% if @comment.errors.any? %>
+ <div id="control-group">
+ <div class="alert alert-error controls ">
+ <a class="close" data-dismiss="alert">×</a>
+ <h4 class="alert-heading"><%= pluralize(@comment.errors.count, "error") %></h4>
+ <% @comment.errors.full_messages.each do |msg| %>
+ <em><%= msg %></em><br>
+ <% end %>
+ </div>
+ </div>
+ <% end %>
+
+
+ <div class="control-group">
+ <%= f.label :commenter, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :commenter, placeholder: 'Your Names', :class => 'span3' %>
+ </div>
+ </div>
+ <div class="control-group">
+ <%= f.label :comment_email, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.email_field :comment_email, placeholder: 'Email - We never publish emails', :class => 'span3' %>
+ </div>
+ </div>
+ <div class="control-group">
+ <%= f.label :comment_email, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.url_field :comment_url, placeholder: 'Website', :class => 'span3' %>
+ </div>
+ </div>
+ <div class="control-group">
+ <%= f.label :content, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_area :content, required: true, placeholder: 'Type your comment here', :class => 'span6', rows: 4 %>
+ </div>
+ </div>
+
+ <div class="form-actions">
+ <%= f.submit nil, :class => 'btn btn-primary' %>
+ </div>
+<% end %>
View
3 app/views/comments/edit.html.erb
@@ -0,0 +1,3 @@
+
+<h1><%=t '.title', :default => "Edit comment for: #{@post.title}" %></h1>
+<%= render :partial => 'form' %>
View
36 app/views/comments/index.html.erb
@@ -0,0 +1,36 @@
+<%- model_class = Comment.new.class -%>
+<h1><%=t '.title', :default => model_class.model_name.human.pluralize %></h1>
+<table class="table table-striped">
+ <thead>
+ <tr>
+ <th><%= model_class.human_attribute_name(:id) %></th>
+ <th><%= model_class.human_attribute_name(:post_id) %></th>
+ <th><%= model_class.human_attribute_name(:commenter) %></th>
+ <th><%= model_class.human_attribute_name(:email) %></th>
+ <th><%= model_class.human_attribute_name(:content) %></th>
+ <th><%= model_class.human_attribute_name(:created_at) %></th>
+ <th><%=t '.actions', :default => t("helpers.actions") %></th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @comments.each do |comment| %>
+ <tr>
+ <td><%= comment.id %></td>
+ <td><%= link_to comment.post_id, post_path(@post) %></td>
+ <td><%= comment.commenter %></td>
+ <td><%= comment.comment_email %></td>
+ <td><%= link_to comment.content, post_comment_path(@post, comment) %></td>
+ <td><%=l comment.created_at %></td>
+ <td>
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
+ edit_post_comment_path(@post, comment), :class => 'btn btn-mini' %>
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
+ post_comment_path(@post, comment),
+ :method => :delete,
+ :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
+ :class => 'btn btn-mini btn-danger' %>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
View
4 app/views/comments/new.html.erb
@@ -0,0 +1,4 @@
+<%- model_class = @comment.class -%>
+<h1><%=t '.title', :default => t('helpers.titles.new', :model => model_class.model_name.human,
+ :default => "New #{model_class.model_name.human}") %></h1>
+<%= render :partial => 'form' %>
View
25 app/views/comments/show.html.erb
@@ -0,0 +1,25 @@
+<article>
+ <h1><%=t '.title', :default => "Article: #{@post.title}" %></h1>
+ <div class="alert alert-success">
+ <strong><%= @comment.commenter %></strong>
+ <% if can? :access, :comments %>
+ <br>
+ <%= @comment.comment_email %>
+ <br>
+ <%= @comment.ip_address_info %>
+ <% end %>
+ </div>
+ <%= markdown @comment.content %>
+</article>
+
+<div class="form-actions">
+ <%= link_to t('.back', :default => t("helpers.links.back")),
+ post_comments_path, :class => 'btn' %>
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
+ edit_post_comment_path(@post, @comment), :class => 'btn' %>
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
+ post_comment_path(@post, @comment),
+ :method => 'delete',
+ :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
+ :class => 'btn btn-danger' %>
+</div>
View
9 app/views/day_trips/index.html.erb
@@ -14,6 +14,9 @@
<%= markdown day_trip.description.truncate(300) %>
<hr>
<% end %>
-<%= link_to t('.new', :default => t("helpers.links.new")),
- new_day_trip_path,
- :class => 'btn btn-primary' %>
+
+<% if can? :access, @day_trips %>
+ <%= link_to t('.new', :default => t("helpers.links.new")),
+ new_day_trip_path,
+ :class => 'btn btn-primary' %>
+<% end %>
View
83 app/views/day_trips/show.html.erb
@@ -2,24 +2,29 @@
<h1><%=t '.title', :default => @day_trip.title %></h1>
<%= markdown @day_trip.description %>
-<div class="form-actions">
- <%= link_to t('.back', :default => t("helpers.links.back")),
- day_trips_path, :class => 'btn' %>
- <%= link_to t('.edit', :default => t("helpers.links.edit")),
- edit_day_trip_path(@day_trip), :class => 'btn' %>
- <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
- day_trip_path(@day_trip),
- :method => 'delete',
- :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
- :class => 'btn btn-danger' %>
+<% if can? :access, @day_trip %>
+ <div class="form-actions">
+ <%= link_to t('.back', :default => t("helpers.links.back")),
+ day_trips_path, :class => 'btn' %>
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
+ edit_day_trip_path(@day_trip), :class => 'btn' %>
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
+ day_trip_path(@day_trip),
+ :method => 'delete',
+ :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
+ :class => 'btn btn-danger' %>
</div>
+<% end %>
+<br>
+
+
<% if !@day_trip.destinations.blank? %>
<h6>Destinations</h6>
<hr>
<% for dt in @day_trip.destinations %>
<h3><%= link_to dt.title, day_trip_destination_path(@day_trip, dt), title: dt.title %></h3>
<%= markdown dt.description.truncate(300) %>
- <p><%= link_to 'Read more...', day_trip_destination_path(@day_trip, dt) %></p>
+ <p><%= link_to 'Read more...', day_trip_destination_path(@day_trip, dt), class: 'btn' %></p>
<% end %>
<% else %>
<div class="alert">
@@ -29,31 +34,35 @@
<% end %>
</article>
<hr>
-<%= form_for [@day_trip, @day_trip.destinations.new], :html => { :class => 'form-horizontal' } do |f| %>
- <h3 class="page-title">Add a new itinerary</h3>
- <br>
- <div class="control-group">
- <%= f.label :title, 'Destination name', :class => 'control-label' %>
- <div class="controls">
- <%= f.text_field :title, :class => 'span3', required: true %>
- </div>
- </div>
- <div class="control-group">
- <%= f.label :price, 'Price breakdown', :class => 'control-label' %>
- <div class="controls">
- <%= f.text_area :price, :class => 'span6', rows: 6 %>
- </div>
- </div>
- <div class="control-group">
- <%= f.label :description, class: 'control-label' %>
- <div class="controls">
- <%= f.text_area :description, class: 'span6', rows: 8 %>
- </div>
- </div>
- <div class="form-actions">
- <%= f.submit nil, :class => 'btn btn-primary' %>
- <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
- day_trips_path, :class => 'btn' %>
- </div>
+
+<% if can? :access, @day_trip %>
+ <%= form_for [@day_trip, @day_trip.destinations.new], :html => { :class => 'form-horizontal' } do |f| %>
+ <h3 class="page-title">Add a new itinerary</h3>
+ <br>
+ <div class="control-group">
+ <%= f.label :title, 'Destination name', :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :title, :class => 'span3', required: true %>
+ </div>
+ </div>
+ <div class="control-group">
+ <%= f.label :price, 'Price breakdown', :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_area :price, :class => 'span6', rows: 6 %>
+ </div>
+ </div>
+ <div class="control-group">
+ <%= f.label :description, class: 'control-label' %>
+ <div class="controls">
+ <%= f.text_area :description, class: 'span6', rows: 8 %>
+ </div>
+ </div>
+
+ <div class="form-actions">
+ <%= f.submit nil, :class => 'btn btn-primary' %>
+ <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
+ day_trips_path, :class => 'btn' %>
+ </div>
+ <% end %>
<% end %>
View
75 app/views/home/index.html.erb
@@ -1,3 +1,76 @@
+
+<!--====================== for checking viewport======================= -->
+<!--======================
+<div id="viewportwidth" class="alert alert-success">
+
+</div>
+<div id="resolutionwidth" class="alert alert-info">
+
+</div>
+
+
+<script type="text/javascript">
+function getViewportWidth()
+{
+ if (window.innerWidth)
+ {
+ return window.innerWidth;
+ }
+ else if (document.body && document.body.offsetWidth)
+ {
+ return document.body.offsetWidth;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+function getViewportHeight()
+{
+ if (window.innerHeight)
+ {
+ return window.innerHeight;
+ }
+ else if (document.body && document.body.offsetHeight)
+ {
+ return document.body.offsetHeight;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+var tellMeTheSizes=function()
+{
+ document.getElementById("viewportwidth").innerHTML = getViewportWidth() + "px";
+ document.getElementById("viewportheight").innerHTML = getViewportHeight() + "px";
+ document.getElementById("resolutionheight").innerHTML = screen.height + "px";
+ document.getElementById("resolutionwidth").innerHTML = screen.width + "px";
+}
+
+window.onload=function()
+{
+ tellMeTheSizes();
+}
+
+window.onresize=function()
+{
+ tellMeTheSizes();
+}
+
+window.onmousemove=function(event)
+{
+ ev = event || window.event;
+ document.getElementById("mousetop").innerHTML = ev.pageY + "px";
+ document.getElementById("mouseleft").innerHTML = ev.pageX + "px";
+}
+</script>
+
+-->
+
+
<div class="row">
<div class="span2">
<p>&nbsp;</p>
@@ -48,7 +121,7 @@
<li><%= link_to "Kit hire", :kit_hire, title: 'Kit hire' %></li>
<li><%= link_to "Itineraries and prices", :itineraries, title: 'Itineraries and prices' %></li>
<li><%= link_to "About Tanzania", :about_tanzania, title: 'About Tanzania' %></li>
- <li><%= link_to "Read our Blog", '#:posts', title: 'Read our Blog' %></li>
+ <li><%= link_to "Read our Blog", :posts, title: 'Read our Blog' %></li>
</ul>
<ul class="quick-links">
<li>LinkedIn </li>
View
5 app/views/layouts/_footer.html.erb
@@ -9,6 +9,11 @@
</footer>
</div> <!-- /container -->
+
+ <!-- Javascripts
+ ================================================== -->
+ <!-- Placed at the end of the document so the pages load faster -->
+ <%= javascript_include_tag "application" %>
<script>
$('.carousel').carousel({
View
54 app/views/layouts/_header.html.erb
@@ -10,10 +10,6 @@
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
<![endif]-->
- <!-- Javascripts
- ================================================== -->
- <!-- Placed at the end of the document so the pages load faster -->
- <%= javascript_include_tag "application" %>
<%= stylesheet_link_tag "application", :media => "all" %>
@@ -39,7 +35,7 @@
<li><%= link_to "Safaris", :safaris %></li>
<li><%= link_to "Beach Destinations", :beaches %></li>
<li><%= link_to "Day Trips", :day_trips %></li>
- <!-- <li><%= link_to "Itineraries", :itineraries %></li> -->
+ <li><%= link_to "Kit Hire", :kit_hire %></li>
</ul>
<!-- .dropdown -->
@@ -50,15 +46,21 @@
<ul class="dropdown-menu">
<li>
<%= form_tag sessions_path, :method => :post, :class => 'well' do %>
- <h6>Login:</h6>
- <div class="controls">
- <%= text_field_tag :username, nil, placeholder: 'Username', autofocus: true %>
- </div>
- <div class="controls">
- <%= password_field_tag :password, nil, placeholder: 'Password' %>
- <p class="help-block"><small><a href="#">Forgot Password?</a></small></p>
- </div>
- <div class="form-actions"><%= submit_tag "Login", class: 'btn btn-primary' %> </div>
+ <h6>Login:</h6>
+ <div class="control-group">
+ <div class="controls">
+ <%= text_field_tag :username, nil, placeholder: 'Username', required: true, autofocus: true %>
+ </div>
+ </div>
+ <div class="control-group">
+ <div class="controls">
+ <%= password_field_tag :password, nil, placeholder: 'Password', required: true %>
+ <p class="help-block"><small><a href="#">Forgot Password?</a></small></p>
+ </div>
+ </div>
+ <div class="form-actions">
+ <%= submit_tag "Login", class: 'btn btn-primary' %>
+ </div>
<% end %>
</li>
</ul>
@@ -105,15 +107,29 @@
</div>
<% end %>
</li>
- </ul>
+
<% else %>
- <ul class="dropdown-menu">
- <li><a href="#">Users</a></li>
- </ul>
+ <li class="dropdown">
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown"><%= current_user.username %> <b class="caret"></b></a>
+ <ul class="dropdown-menu">
+ <li><%= link_to "My Account", user_path(current_user) %></li>
+ <% if can? :access, @user %>
+ <li class="divider-horizontal"></li>
+ <li><%= link_to "Manage Users", users_path %></li>
+ <% end %>
+ </ul>
+ </li>
+ </ul>
<% end %>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
- </div>
+ </div>
+
+ <% flash.each do |name, msg| %>
+ <div class="container">
+ <%= content_tag :div, msg, :id => "flash_#{name}", :class => "alert alert-#{name}" %>
+ </div>
+ <% end %>
View
25 app/views/layouts/application.html.erb
@@ -3,10 +3,6 @@
<div class="container">
<div class="content">
- <% if !("welcome#index") %>
- <%= yield %>
- <% else %>
-
<div class="row">
<div class="span9">
<%= yield %>
@@ -15,17 +11,20 @@
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Important links</li>
- <li><%= link_to "Galleries", :albums %></li>
- <li><%= link_to "Accommodation", "#" %></li>
- <li><%= link_to "About Tanzania", :about_tanzania %></li>
- <li><%= link_to "Important Information", :important_information %></li>
- <li><%= link_to "About Us", :about_us %></li>
- <li><%= link_to "Contact Us", :contact_us %></li>
- <li><%= link_to "Guides and porters", :guides_and_porters %></li>
+ <li><%= link_to "Accommodation", :accommodation, title: 'Accommodation information' %></li>
+ <li><%= link_to "Important information", :important_information, title: 'Important information for tourists' %></li>
+ <li><%= link_to "Guides and porters", :guides_and_porters, title: 'Our tour guides and porters' %></li>
+ <li><%= link_to "About Tanzania", :about_tanzania, title: 'About Tanzania' %></li>
+ <li><%= link_to "Contact us", :contact_us, title: 'Contact Us' %></li>
+ <li><%= link_to "Newsletter", ':newsletters', title: 'Subscribe to our newsletter' %></li>
+ <li><%= link_to "About us", :about_us, title: 'About us' %></li>
+ <li><%= link_to "Galleries", :albums, title: 'Photo galleries' %></li>
+ <li><%= link_to "Blog", :posts, title: 'Read the blog' %></li>
+
</ul>
</div><!--/.well -->
</div><!--/span-->
</div><!--/row-->
</div><!--/content-->
- <% end %>
-<%= render 'layouts/footer' %>
+
+<%= render 'layouts/footer' %>
View
9 app/views/photos/index.html.erb
@@ -1,9 +1,12 @@
<%- model_class = Photo.new.class -%>
<h1>
<%=t '.title', :default => "Album: #{@album.title}" %>
-<%= link_to t('.new', :default => t("helpers.links.add_photo")),
- new_album_photo_path(@album),
- :class => 'btn btn-primary pull-right' %>
+
+<% if can? :access, @photos %>
+ <%= link_to t('.new', :default => t("helpers.links.add_photo")),
+ new_album_photo_path(@album),
+ :class => 'btn btn-primary pull-right' %>
+<% end %>
</h1>
<hr>
View
23 app/views/photos/show.html.erb
@@ -9,14 +9,17 @@
<%= @photo.caption %>
</p>
-<div class="form-actions">
- <%= link_to t('.back', :default => t("helpers.links.back")),
- album_photos_path(@album), :class => 'btn' %>
- <%= link_to t('.edit', :default => t("helpers.links.edit")),
- edit_album_photo_path(@album, @photo), :class => 'btn' %>
- <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
- album_photo_path(@album, @photo),
- :method => 'delete',
- :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
- :class => 'btn btn-danger' %>
+
+<% if can? :access, @photo %>
+ <div class="form-actions">
+ <%= link_to t('.back', :default => t("helpers.links.back")),
+ album_photos_path(@album), :class => 'btn' %>
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
+ edit_album_photo_path(@album, @photo), :class => 'btn' %>
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
+ album_photo_path(@album, @photo),
+ :method => 'delete',
+ :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
+ :class => 'btn btn-danger' %>
</div>
+<% end %>
View
47 app/views/posts/_form.html.erb
@@ -0,0 +1,47 @@
+<%= form_for @post, :html => { :class => 'form-horizontal' } do |f| %>
+
+ <% if @post.errors.any? %>
+ <div id="control-group">
+ <div class="alert alert-error controls ">
+ <a class="close" data-dismiss="alert">×</a>
+ <h4 class="alert-heading"><%= pluralize(@post.errors.count, "error") %></h4>
+ <% @post.errors.full_messages.each do |msg| %>
+ <em><%= msg %></em><br>
+ <% end %>
+ </div>
+ </div>
+ <% end %>
+
+
+ <div class="control-group">
+ <%= f.label :title, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :title, required: true, :class => 'span6' %>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <%= f.label :content, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_area :content, :class => 'span7', rows: 9, required: true %>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <%= f.label :published, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.check_box :published %>
+ </div>
+ </div>
+ <div class="control-group">
+ <%= f.label :ban_comments, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.check_box :ban_comments, :class => 'check_box' %>
+ </div>
+ </div>
+ <div class="form-actions">
+ <%= f.submit nil, :class => 'btn btn-primary' %>
+ <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
+ posts_path, :class => 'btn' %>
+ </div>
+<% end %>
View
4 app/views/posts/edit.html.erb
@@ -0,0 +1,4 @@
+<%- model_class = @post.class -%>
+<h1><%=t '.title', :default => t('helpers.titles.edit', :model => model_class.model_name.human,
+ :default => "Edit #{model_class.model_name.human}") %></h1>
+<%= render :partial => 'form' %>
View
21 app/views/posts/index.html.erb
@@ -0,0 +1,21 @@
+
+<% if can? :access, @posts %>
+<p class="alert alert-success"><%= link_to t('.new', :default => t("helpers.links.new_post")),
+ new_post_path,
+ :class => 'btn btn-primary' %></p>
+<% end %>
+
+<% @posts.each do |post| %>
+ <article>
+ <h1><%= link_to post.title, post_path(post), title: post.title %></h1>
+ <p>
+ <small>
+ <%= time_tag post.published, format: '%m %b %Y', pubdate: true if post.published? %>
+ <b>By:</b> <%= link_to post.user.full_name, user_path(post.user), title: post.user.full_name %>
+ &bull;
+ <i>(<%= post.comments.count %>) Comments</i>
+ </small>
+ </p>
+ <%= markdown post.content %>
+ </article>
+<% end %>
View
4 app/views/posts/new.html.erb
@@ -0,0 +1,4 @@
+<%- model_class = @post.class -%>
+<h1><%=t '.title', :default => t('helpers.titles.new', :model => model_class.model_name.human,
+ :default => "New #{model_class.model_name.human}") %></h1>
+<%= render :partial => 'form' %>
View
106 app/views/posts/show.html.erb
@@ -0,0 +1,106 @@
+<%- model_class = @post.class -%>
+<h1><%=t '.title', :default => @post.title, title: @post.title %></h1>
+
+<p><small><%= time_tag @post.published, format: '%m %b %Y', pubdate: true if @post.published? %> <b>By:</b> <%= link_to @post.user.full_name, user_path(@post.user), title: @post.user.full_name %></small></p>
+
+
+<article>
+ <%= markdown @post.content %>
+
+ <% if can? :access, :posts %>
+ <p class="alert alert-success"><strong>IP address information:</strong> <%= @post.ip_address_info %></p>
+ <% end %>
+</article>
+
+<% if can? :update, :posts %>
+ <div class="form-actions">
+ <%= link_to t('.back', :default => t("helpers.links.back")),
+ posts_path, :class => 'btn' %>
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
+ edit_post_path(@post), :class => 'btn' %>
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
+ post_path(@post),
+ :method => 'delete',
+ :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
+ :class => 'btn btn-danger' %>
+ </div>
+<% end %>
+
+<!-- ======Comments roll====== -->
+<h3>Comments:</h3>
+<% if !@comments.blank? %>
+ <% for comment in @comments %>
+ <table class="table">
+ <tr>
+ <td class="span2">
+ <p><%= link_to comment.commenter, comment.comment_url? ? comment.comment_url : '#', title: comment.commenter, target: '_blank' %><br>
+ <small><%= distance_of_time_in_words comment.created_at, Time.now %> ago</small></p>
+ </td>
+ <td><%= markdown comment.content %></td>
+ </tr>
+ </table>
+ <% end %>
+<% else %>
+ <p>No Comments, Be the first to comment.</p>
+<% end %>
+
+<hr>
+<!-- ===Comments form=== -->
+
+<% if @post.ban_comments? %>
+ <section class="well">
+ <p class="alert alert-info"><strong>Sorry!</strong> Commenting has been disabled on this article.</p>
+ </section>
+ <% else %>
+
+ <section class="well">
+ <%= form_for [@post, @comment], :html => { :class => 'form-horizontal' } do |f| %>
+ <fieldset id="leave_a_comment" class="">
+ <legend>Leave a comment</legend>
+ <% if logged_in? %>
+ <div class="control-group">
+ <%= f.label :commenter, 'Your names', :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :commenter, required: true, value: current_user.full_name, :class => 'span3' %>
+ </div>
+ </div>
+ <div class="control-group">
+ <%= f.label :comment_email, 'Your e-mail', :class => 'control-label' %>
+ <div class="controls">
+ <%= f.email_field :comment_email, required: true, value: current_user.email, :class => 'span3' %>
+ </div>
+ </div>
+ <% else %>
+ <div class="control-group">
+ <%= f.label :commenter, 'Your names', :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :commenter, required: true, placeholder: 'Your Names', :class => 'span3' %>
+ </div>
+ </div>
+ <div class="control-group">
+ <%= f.label :comment_email, 'Your e-mail', :class => 'control-label' %>
+ <div class="controls">
+ <%= f.email_field :comment_email, required: true, placeholder: 'Email - We never publish emails', :class => 'span3' %>
+ </div>
+ </div>
+ <% end %>
+ <div class="control-group">
+ <%= f.label :comment_url, 'Your website', :class => 'control-label' %>
+ <div class="controls">
+ <%= f.url_field :comment_url, placeholder: 'Website (optional)', :class => 'span3' %>
+ </div>
+ </div>
+ <div class="control-group">
+ <%= f.label :content, 'Your comment', :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_area :content, required: true, placeholder: 'Type your comment here', :class => 'span6', rows: 5 %>
+ </div>
+ </div>
+
+ <div class="form-actions">
+ <%= f.submit nil, :class => 'btn btn-primary' %>
+ </div>
+ </fieldset>
+ <% end %>
+ </section>
+<% end %>
View
9 app/views/safaris/index.html.erb
@@ -10,6 +10,9 @@
<hr>
<% end %>
-<%= link_to t('.new', :default => t("helpers.links.add_another_safari")),
- new_safari_path,
- :class => 'btn btn-primary' %>
+
+<% if can? :access, @safaris %>
+ <%= link_to t('.new', :default => t("helpers.links.add_another_safari")),
+ new_safari_path,
+ :class => 'btn btn-primary' %>
+<% end %>
View
85 app/views/safaris/show.html.erb
@@ -3,18 +3,22 @@
<%= markdown @safari.description %>
-<div class="form-actions">
- <%= link_to t('.back', :default => t("helpers.links.back")),
- safaris_path, :class => 'btn' %>
- <%= link_to t('.edit', :default => t("helpers.links.edit")),
- edit_safari_path(@safari), :class => 'btn' %>
- <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
- safari_path(@safari),
- :method => 'delete',
- :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
- :class => 'btn btn-danger' %>
+
+<% if can? :access, @safari %>
+ <div class="form-actions">
+ <%= link_to t('.back', :default => t("helpers.links.back")),
+ safaris_path, :class => 'btn' %>
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
+ edit_safari_path(@safari), :class => 'btn' %>
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
+ safari_path(@safari),
+ :method => 'delete',
+ :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
+ :class => 'btn btn-danger' %>
</div>
-<br>
+<% end %>
+
+
<article class="">
<% if !@safari.destinations.blank? %>
<h6>Destinations</h6>
@@ -22,7 +26,7 @@
<% for dt in @safari.destinations %>
<h3><%= link_to dt.title, safari_destination_path(@safari, dt), title: dt.title %></h3>
<%= markdown dt.description.truncate(300) %>
- <p><%= link_to 'Read more...', safari_destination_path(@safari, dt) %></p>
+ <p><%= link_to 'Read more...', safari_destination_path(@safari, dt), class: 'btn' %></p>
<% end %>
<% else %>
<div class="alert">
@@ -32,31 +36,36 @@
<% end %>
</article>
<hr>
-<%= form_for [@safari, @safari.destinations.new], :html => { :class => 'form-horizontal' } do |f| %>
- <h3 class="page-title">Add a new itinerary</h3>
- <br>
- <div class="control-group">
- <%= f.label :title, 'Destination name', :class => 'control-label' %>
- <div class="controls">
- <%= f.text_field :title, :class => 'span3', required: true %>
- </div>
- </div>
- <div class="control-group">
- <%= f.label :price, 'Price breakdown', :class => 'control-label' %>
- <div class="controls">
- <%= f.text_area :price, :class => 'span6', rows: 6 %>
- </div>
- </div>
- <div class="control-group">
- <%= f.label :description, class: 'control-label' %>
- <div class="controls">
- <%= f.text_area :description, class: 'span6', rows: 8 %>
- </div>
- </div>
- <div class="form-actions">
- <%= f.submit nil, :class => 'btn btn-primary' %>
- <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
- safaris_path, :class => 'btn' %>
- </div>
+
+<% if can? :access, @safari %>
+<!-- Permissions for admins to as they please -->
+ <%= form_for [@safari, @safari.destinations.new], :html => { :class => 'form-horizontal' } do |f| %>
+ <h3 class="page-title">Add a new itinerary</h3>
+ <br>
+ <div class="control-group">
+ <%= f.label :title, 'Destination name', :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :title, :class => 'span3', required: true %>
+ </div>
+ </div>
+ <div class="control-group">
+ <%= f.label :price, 'Price breakdown', :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_area :price, :class => 'span6', rows: 6 %>
+ </div>
+ </div>
+ <div class="control-group">
+ <%= f.label :description, class: 'control-label' %>
+ <div class="controls">
+ <%= f.text_area :description, class: 'span6', rows: 8 %>
+ </div>
+ </div>
+
+ <div class="form-actions">
+ <%= f.submit nil, :class => 'btn btn-primary' %>
+ <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
+ safaris_path, :class => 'btn' %>
+ </div>
+ <% end %>
<% end %>
View
19 app/views/sessions/new.html.erb
@@ -0,0 +1,19 @@
+<h1>Login:</h1>
+<%= form_tag sessions_path, :method => :post, class: 'form-horizontal' do %>
+ <div class="control-group">
+ <%= label_tag :username, nil, class: 'control-label' %>
+ <div class="controls">
+ <%= text_field_tag :username, nil, placeholder: 'Username' %>
+ </div>
+ </div>
+ <div class="control-group">
+ <%= label_tag :password, nil, class: 'control-label' %>
+ <div class="controls">
+ <%= password_field_tag :password, nil, placeholder: 'Password' %>
+ </div>
+ </div>
+
+ <div class="form-actions">
+ <%= submit_tag "Login", class: 'btn btn-primary' %>
+ </div>
+<% end %>
View
10 app/views/treks/index.html.erb
@@ -12,7 +12,9 @@
-
-<%= link_to t('.new', :default => t("helpers.links.add_a_new_trek")),
- new_trek_path,
- :class => 'btn btn-primary' %>
+<% if can? :access, @treks %>
+ <!-- Permissions for Admins and Moderators -->
+ <%= link_to t('.new', :default => t("helpers.links.add_a_new_trek")),
+ new_trek_path,
+ :class => 'btn btn-primary' %>
+<% end %>
View
86 app/views/treks/show.html.erb
@@ -2,18 +2,22 @@
<h1><%=t '.title', :default => @trek.title %></h1>
<%= markdown @trek.description %>
+
+<% if can? :access, @trek %>
+ <div class="form-actions">
+ <%= link_to t('.back', :default => t("helpers.links.back")),
+ treks_path, :class => 'btn' %>
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
+ edit_trek_path(@trek), :class => 'btn' %>
+ <%= link_to t('.destroy', :default => t("helpers.links.delete")),
+ trek_path(@trek),
+ :method => 'delete'</