Skip to content

Commit f5be348

Browse files
committed
Merge pull request coderwall#139 from sao/master
Better 404’s
2 parents 28b7dd7 + 27ff577 commit f5be348

File tree

9 files changed

+87
-40
lines changed

9 files changed

+87
-40
lines changed

app/assets/stylesheets/application.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@import "normailze";
55
@import "tipTip";
66
@import "new-new-home";
7+
@import "error";
78

89
.user-mosaic, .team-mosiac {
910
float: left;
@@ -619,7 +620,7 @@ body#sign-in {
619620
width: 940px;
620621
margin: 50px auto 75px auto;
621622
text-align: center;
622-
623+
623624
h2 {
624625
color: #777;
625626
text-transform: uppercase;

app/assets/stylesheets/error.scss

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
.error-body {
2+
p.error-desc {
3+
margin: 20px 0 40px;
4+
font-size: 16px;
5+
line-height: 2;
6+
a {
7+
color: #000;
8+
border-bottom: 1px solid #000;
9+
}
10+
}
11+
}
12+
13+
.column {
14+
display: inline-block;
15+
&.popular-list {
16+
background: #FFF;
17+
padding: 20px;
18+
box-sizing: border-box;
19+
h3 {
20+
margin-bottom: 10px;
21+
}
22+
ol {
23+
list-style-type: decimal;
24+
line-height: 2;
25+
margin-left: 20px;
26+
li {
27+
font-size: 16px;
28+
a {
29+
color: #000;
30+
border-bottom: 1px solid #000;
31+
}
32+
}
33+
}
34+
}
35+
&.signup-list {
36+
background: #3a3a3a;
37+
width: 525px;
38+
padding: 3em 4em;
39+
-o-border-radius: 4px;
40+
border-radius: 4px;
41+
margin: 0 0 0 40px;
42+
overflow: hidden;
43+
@include sign-up-btns;
44+
.sign-btns {
45+
text-align: center;
46+
li {
47+
float: none;
48+
display: inline-block;
49+
}
50+
}
51+
}
52+
}

app/assets/stylesheets/new-new-home.scss

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@
306306
.content .avatar {
307307
margin-top: 1em;
308308
}
309-
}
309+
}
310310

311311
.tip-sidebar {
312312
width: 30%;
@@ -1380,8 +1380,6 @@
13801380
.join-panel {
13811381
text-align: center;
13821382
float: none;
1383-
.sign-btns {
1384-
}
13851383
}
13861384
}
13871385
}

app/controllers/application_controller.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,11 @@ def not_on_achievements?
173173
params[:controller] != 'achievements'
174174
end
175175

176-
unless Rails.env.development? || Rails.env.test?
177-
rescue_from(ActiveRecord::RecordNotFound) { |e| render_404 }
178-
rescue_from(ActionController::RoutingError) { |e| render_404 }
179-
# rescue_from(RuntimeError) { |e| render_500 }
180-
end
176+
rescue_from ActiveRecord::RecordNotFound, with: :render_404
177+
rescue_from ActionController::RoutingError, with: :render_404
181178

182179
def render_404
183-
respond_to do |type|
184-
type.html { render file: File.join(Rails.root, 'public', '404.html'), layout: nil, status: 404 }
185-
type.all { render nothing: true, status: 404 }
186-
end
180+
render template: 'error/not_found', status: :not_found
187181
end
188182

189183
def render_500

app/helpers/error_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module ErrorHelper
2+
def protips_list(type, count)
3+
Protip.method(type).call.first(count)
4+
end
5+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
%div.columns
2+
%div.column.popular-list
3+
%h3="Top 5 Most Popular Protips"
4+
%ol
5+
- protips_list(:trending, 5).each do |protip|
6+
%li
7+
=link_to "#{protip.title} by #{protip.user.name}", protip_path(protip.public_id)
8+
%div.column.signup-list
9+
=render :partial => "sessions/join_buttons", :locals => {:message => "Join to start earning badges for your open source contributions, discover protips and connect with other developers"}

app/views/error/not_found.html.haml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
%div.error-body
2+
%section.not-found
3+
%header.cf
4+
%h2 Uh oh, something went wrong!
5+
%p.error-desc
6+
Unfortunately, you are looking for something that isn't here. Maybe we can help you find something?
7+
Use the links below to check out a few of the most popular protips or
8+
#{ link_to "sign up and start submitting your own protips", signin_path }.
9+
If you don't believe you should be seeing this error,
10+
#{ link_to "please contact us", contact_us_path }!
11+
12+
= render partial: "error/helpful_links"
13+

config/environments/development.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Coderwall::Application.configure do
22
config.threadsafe! unless $rails_rake_task
3-
3+
44
require 'sidekiq/testing/inline'
55

66
config.action_controller.perform_caching = false
@@ -27,6 +27,6 @@
2727
config.cache_store = [:file_store,"/tmp/codewall-cache/"]
2828
config.assets.cache_store = [:file_store,"/tmp/codewall-cache/assets/"]
2929
Rails.application.config.sass.cache_location = "/tmp/codewall-cache/sass/"
30-
30+
3131
BetterErrors::Middleware.allow_ip! ENV['TRUSTED_IP'] if ENV['TRUSTED_IP']
3232
end

public/404.html

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)