rails_fix_google_bot_accept 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/rails_fix_google_bot_accept/google_bot_aware.rb +29 -0
- data/lib/rails_fix_google_bot_accept/railtie.rb +7 -0
- data/lib/rails_fix_google_bot_accept/version.rb +3 -0
- data/lib/rails_fix_google_bot_accept.rb +34 -0
- data/rails_fix_google_bot_accept.gemspec +19 -0
- metadata +58 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Michael Witrant
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# RailsFixGoogleBotAccept
|
2
|
+
|
3
|
+
This gem fixes the `ActionView::MissingTemplate` error generated by Rails when a page is requested with the header `Accept: */*;q=0.9` (or any other number).
|
4
|
+
The Google bot does such requests.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'rails_fix_google_bot_accept'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
That's it.
|
17
|
+
|
18
|
+
## Source
|
19
|
+
|
20
|
+
The gem is based on this gist: https://gist.github.com/2590040/93cb2faca1ba5ead73222e74ca11790e3efb22de
|
21
|
+
It was made by Romain Champourlier as an answer to this question: http://stackoverflow.com/questions/8881756/googlebot-receiving-missing-template-error-for-an-existing-template
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RailsFixGoogleBotAccept
|
2
|
+
# This Rack middleware helps solving the issue with some Rails versions which do not accept
|
3
|
+
# a '*/*;q=0.6' and their variants 'Accept' request header. This header is particularly used
|
4
|
+
# by Google Bot, and if Rails doesn't like it, it will return a 500 or 406 error to Google Bot,
|
5
|
+
# which is not the best way to get your pages indexed.
|
6
|
+
#
|
7
|
+
# References:
|
8
|
+
# - http://stackoverflow.com/questions/8881756/googlebot-receiving-missing-template-error-for-an-existing-template
|
9
|
+
# - https://github.com/rails/rails/issues/4127
|
10
|
+
#
|
11
|
+
class GoogleBotAware
|
12
|
+
|
13
|
+
def initialize(app)
|
14
|
+
@app = app
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
# If the request 'Content Accept' header indicates a '*/*' format,
|
19
|
+
# we set the format to :html.
|
20
|
+
# This is necessary for GoogleBot which requests / with '*/*;q=0.6' for example.
|
21
|
+
if env["HTTP_ACCEPT"] =~ %r%\*\/\*;q=\d\.\d%
|
22
|
+
env["HTTP_ACCEPT"] = '*/*'
|
23
|
+
end
|
24
|
+
|
25
|
+
@app.call(env)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "rails_fix_google_bot_accept/version"
|
2
|
+
|
3
|
+
require 'rails_fix_google_bot_accept/google_bot_aware'
|
4
|
+
require "rails_fix_google_bot_accept/railtie" if defined? Rails
|
5
|
+
|
6
|
+
module RailsFixGoogleBotAccept
|
7
|
+
# This Rack middleware helps solving the issue with some Rails versions which do not accept
|
8
|
+
# a '*/*;q=0.6' and their variants 'Accept' request header. This header is particularly used
|
9
|
+
# by Google Bot, and if Rails doesn't like it, it will return a 500 or 406 error to Google Bot,
|
10
|
+
# which is not the best way to get your pages indexed.
|
11
|
+
#
|
12
|
+
# References:
|
13
|
+
# - http://stackoverflow.com/questions/8881756/googlebot-receiving-missing-template-error-for-an-existing-template
|
14
|
+
# - https://github.com/rails/rails/issues/4127
|
15
|
+
#
|
16
|
+
class GoogleBotAware
|
17
|
+
|
18
|
+
def initialize(app)
|
19
|
+
@app = app
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(env)
|
23
|
+
# If the request 'Content Accept' header indicates a '*/*' format,
|
24
|
+
# we set the format to :html.
|
25
|
+
# This is necessary for GoogleBot which requests / with '*/*;q=0.6' for example.
|
26
|
+
if env["HTTP_ACCEPT"] =~ %r%\*\/\*;q=\d\.\d%
|
27
|
+
env["HTTP_ACCEPT"] = '*/*'
|
28
|
+
end
|
29
|
+
|
30
|
+
@app.call(env)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rails_fix_google_bot_accept/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "rails_fix_google_bot_accept"
|
8
|
+
gem.version = RailsFixGoogleBotAccept::VERSION
|
9
|
+
gem.authors = ["Ouvrages", "Romain Champourlier"]
|
10
|
+
gem.email = ["contact@ouvrages-web.fr"]
|
11
|
+
gem.description = %q{Rails fix for Google bot requests}
|
12
|
+
gem.summary = %q{This gem fixes the `ActionView::MissingTemplate` error generated by Rails when a page is requested with the header `Accept: */*;q=0.9` (or any other number).}
|
13
|
+
gem.homepage = "https://github.com/ouvrages/rails_fix_google_bot_accept"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_fix_google_bot_accept
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ouvrages
|
9
|
+
- Romain Champourlier
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-02-11 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: Rails fix for Google bot requests
|
16
|
+
email:
|
17
|
+
- contact@ouvrages-web.fr
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- lib/rails_fix_google_bot_accept.rb
|
28
|
+
- lib/rails_fix_google_bot_accept/google_bot_aware.rb
|
29
|
+
- lib/rails_fix_google_bot_accept/railtie.rb
|
30
|
+
- lib/rails_fix_google_bot_accept/version.rb
|
31
|
+
- rails_fix_google_bot_accept.gemspec
|
32
|
+
homepage: https://github.com/ouvrages/rails_fix_google_bot_accept
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.8.11
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: ! 'This gem fixes the `ActionView::MissingTemplate` error generated by Rails
|
56
|
+
when a page is requested with the header `Accept: */*;q=0.9` (or any other number).'
|
57
|
+
test_files: []
|
58
|
+
has_rdoc:
|