Comments (4)
Hi there,
I'm glad you enjoy the gem :) Your problem here is easily solved by using named variables rather than instance variables. Because @website_id looks for the website_id on the current instance (context) which changes as you have seen from your output. So just replace @website_id
with website_id
, @website
with website
etc.
from sitemap_generator.
-1.Thank you for answer, this is working for me, here is code:
def export_sitemap
# Init variables
website = @website
website_id = @website_id
# Create sitemap files
SitemapGenerator::Sitemap.default_host = @website.domain
SitemapGenerator::Sitemap.public_path = "tmp/"
SitemapGenerator::Sitemap.sitemaps_path = "sitemaps/#{@website.code}"
SitemapGenerator::Sitemap.adapter = SitemapGenerator::WaveAdapter.new
SitemapGenerator::Sitemap.create do |interpreter|
puts 'test1' + @website_id.inspect
puts 'test2' + website_id.inspect
StaticContent.find(:all, :conditions => ["website_id = ?", website_id]).each do |item|
interpreter.add item.url
end
end
end
output
test1nil
test21
test1nil
test22
test1nil
test23
I would be great add this use case to documenation, it would be save me about 6 hours.
-2.Also this problem has other solution: if def self.yield_sitemap? return true, then interpreter.eval(:yield_sitemap => @yield_sitemap || SitemapGenerator.yield_sitemap?, &block) get true and then interpretator eval is executed on the right context (context where @website is defined) and I should not create a named variable.
def eval(opts={}, &block)
if block_given?
if opts[:yield_sitemap]
yield self
else
instance_eval(&block)
end
end
end
I have created an initializer with code (monkey patching):
module SitemapGenerator
Returns true if we should yield the sitemap instance to the block, false otherwise.
def self.yield_sitemap?
# Retrun true always
#!!@yeild_sitemap
true
end
end
and solution is working fine for me. I am not able to unerstand how can I setup @yeild_sitemap to true without monkey patching. I will appretiate the answer and it would be greate to add a little note to documentation.
Meantime the problem is resolved and I am ready to close this issue. Thank you very much for answer and for gem!
Sincerely yours,
Rufanov Artem.
P.S.
Have a good day!
from sitemap_generator.
Actually there is already documentation in the README. Take a look at the Generating Multiple Sitemaps section.
I don't understand why you are using the :yield_sitemap
option? You don't need to use that option. It's just there for backwards compatibility with the old version which passed the sitemap to the block. Just use the example I pasted in.
So your create call should look like this:
SitemapGenerator::Sitemap.create do
StaticContent.find(:all, :conditions => ["website_id = ?", website_id]).each do |item|
add item.url # you should be adding a path
end
end
Also you should be passing a path in your call to add()
. The full url is built from the default_host and the path.
BTW it's very simple to set yield_sitemap, but you don't need to use it: SitemapGenerator.yield_sitemap = true
from sitemap_generator.
Thank you very much!
from sitemap_generator.
Related Issues (20)
- Ping failed for Bing: #<OpenURI::HTTPError: 410 Gone> HOT 2
- Feature Request: Remove unwanted options HOT 6
- Is it possible to override the default link options? HOT 3
- How to remove default priority, lastmod and changefreq from all urls HOT 1
- GoogleStorageAdapter - Can't create sitemap on buckets with uniform bucket-level access enabled HOT 3
- Allow disable acl for S3 bucket HOT 1
- Rails on Heroku with S3 sitemap hosting - google didn't like it HOT 2
- 【Worked】Ping failed for Bing: #<OpenURI::HTTPError: 410 Gone> HOT 4
- Is it possible to add additional metadata fields to the xml HOT 5
- Feature request : Make `default_host` optional / Allow full URL instead of path HOT 2
- Entity escaping in XML output
- google search console couldn't fetch sitemap but index is ok HOT 7
- Google search correct ping url HOT 2
- Readme install instructions fail HOT 1
- [BUG] Mobile sitemap link in Readme.md is giving 404
- TimeZone is ignored
- sitemap.xml.gz file not found on server
- Testing with frozen time does not work
- should sitemap show up automatically in google search console? HOT 2
- Should we drop default `lastmod` of `Time.now` as Google says "it needs to consistently match reality"? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sitemap_generator.