Rails Sitemap_Generator Uninitialized Constant

Cannot connect to the model by rails sitemap_generator gem?

I always run it through the rake task, try this:

rake sitemap:refresh:no_ping

It's possible the rake task does the magic to make the application code available when that's running.

Update: probably a duplicate of Rails sitemap_generator Uninitialized Constant? (sorry I should have looked first)

Using sitemap_generator with different locale urls

[:en, :es].each do |locale|
Product.find_each do |product|
add url_for(:controller => 'products', :action => 'show', :id => product, :host => '', :only_path => true, :locale => locale), :lastmod => product.updated_at
end
end

Rails Sitemap_generator using aws_fog configuration

I am also using sitemap-generator gem on my rails application (heroku hosted and rails 6). I have the following code inside config/sitemap.rb, before SitemapGenerator::Sitemap.create. I have configured it with aws-sdk-s3 gem and it goes like this:

require 'aws-sdk-s3'
SitemapGenerator::Sitemap.default_host = "https://www.example.com"
SitemapGenerator::Sitemap.sitemaps_host = 'https://example.s3.eu-west-2.amazonaws.com/'
SitemapGenerator::Sitemap.adapter = SitemapGenerator::AwsSdkAdapter.new(Rails.application.credentials.dig(:amazon, :s3, :bucket),
aws_access_key_id: Rails.application.credentials.dig(:amazon, :s3, :access_key_id),
aws_secret_access_key: Rails.application.credentials.dig(:amazon, :s3, :secret_access_key),
aws_region: Rails.application.credentials.dig(:amazon, :s3, :region)
)

Write adapter for microsoft azure in sitemap_generator

I copied my setup from the S3 adapter and from Azure's ruby example

Add the azure blob gem to your Gemfile:
gem 'azure-storage-blob'

create config/initializers/sitemap_generator/azure_adapter.rb:

require 'azure/storage/blob'

module SitemapGenerator
# Class for uploading sitemaps to Azure blobs using azure-storage-blob gem.
class AzureAdapter
#
# @option :storage_account_name [String] Your Azure access key id
# @option :storage_access_key [String] Your Azure secret access key
# @option :container [String]
def initialize
@storage_account_name = 'your account name'
@storage_access_key = 'your key'
@container = 'your container name (created already in Azure)'
end

# Call with a SitemapLocation and string data
def write(location, raw_data)
SitemapGenerator::FileAdapter.new.write(location, raw_data)

credentials = {
storage_account_name: @storage_account_name,
storage_access_key: @storage_access_key
}

client = Azure::Storage::Blob::BlobService.create(credentials)
container = @container
content = ::File.open(location.path, 'rb') { |file| file.read }
client.create_block_blob(container, location.filename, content)
end
end
end
  • Make sure the container you create in Azure is a 'blob' container so the container is not public but the blobs within are.

and then in config/sitemaps.rb:

SitemapGenerator::Sitemap.sitemaps_host = 'https://[your-azure-address].blob.core.windows.net/'
SitemapGenerator::Sitemap.sitemaps_path = '[your-container-name]/'
SitemapGenerator::Sitemap.adapter = SitemapGenerator::AzureAdapter.new

That should do it!



Related Topics



Leave a reply



Submit