I have a ROR apps that selling items such as chair, table etc. I am using gem sitemap_generator to generate the sitemap. Here is the code of my sitemap:
# Set the host name for URL creation
SitemapGenerator::Sitemap.default_host = "http://www.example.com"
SitemapGenerator::Sitemap.create do
add '/products', :priority => 0.7, :changefreq => 'daily'
end
When I run the command rake sitemap:refresh a sitemap.xml.gz is created in public folder.
My robots.txt as follow:
# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
# User-agent: *
# Disallow: /
Sitemap: http://www.example.com/sitemap.xml.gz
Would this mean, all my products at www.example.com/products will be available for google to index?
Thanks!!
Firstly, you're better off using the url helpers rather than explicit paths. This way if the paths ever change due to modifications to your routes.rb file, you wont need to worry about your sitemap being wrong:
SitemapGenerator::Sitemap.create do
add products_url, priority: 0.7, changefreq: 'daily'
end
Next, the products url you've added above will only add /products to your sitemap. You might want to add each individual product, depending on the frequency of them changing:
SitemapGenerator::Sitemap.create do
add products_path, priority: 0.7, changefreq: 'daily'
Product.all.each do |product|
add product_path(product), priority: 0.7, changefreq: 'daily'
end
end
Obviously, you will need to trigger a sitemap refresh each time you add/remove a product.
Related
i built a simple sitemap with the gem sitemap generator.
It is supposed to list the job pages of my application.
E.g. www.mydomain.com/vacancies/24
There is a bug that I cannot fix myself for days:
It shows the wrong indexes (that do not exist). E.g.
www.mydomain.com/vacancies/645
enter code hereHere is my sitemap.rb file:
require 'rubygems'
require 'sitemap_generator'
SitemapGenerator::Sitemap.default_host = "http://www.frankfurtstartupjobs.com"
SitemapGenerator::Sitemap.create do
Vacancy.find_each do |vacancy|
add vacancy_path(vacancy), :lastmod => vacancy.updated_at, :priority => 0.5
end
end
The sitemap is storing links I made in development. How can the links be taken from production?
$ rake sitemap:create
In '/Users/galli01anthony/Dropbox/LiveToChallenge/public/sitemaps/':
+ sitemap.xml.gz 133 links / 2.09 KB
Sitemap stats: 133 links / 1 sitemaps / 0m02s
Pinging with URL 'http://www.livetochallenge.com/sitemap.xml.gz':
Successful ping of Google
Successful ping of Bing
The default_host is correct, but it is showing links like http://www.livetochallenge.com/challenges/19-test, which doesn't exist in production. http://0.0.0.0:3000/challenges/19-test only exists in development.
sitemap.rb
SitemapGenerator::Sitemap.default_host = 'http://www.livetochallenge.com/'
SitemapGenerator::Sitemap.public_path = 'public/sitemaps/'
SitemapGenerator::Sitemap.create do
add posts_path, changefreq: 'daily'
add challenges_path, changefreq: 'daily'
add inspirations_path, changefreq: 'weekly'
add users_path, changefreq: 'weekly'
add activities_path, changefreq: 'weekly'
add about_path, changefreq: 'monthly'
Post.find_each do |f|
add post_path(f.slug), lastmod: f.updated_at
end
Challenge.find_each do |f|
add challenge_path(f), lastmod: f.updated_at
end
Inspiration.find_each do |f|
add inspiration_path(f), lastmod: f.updated_at
end
User.find_each do |f|
add user_path(f), lastmod: f.updated_at
end
end
SitemapGenerator::Sitemap.ping_search_engines
It looks like you're running the rake task in your development environment so it's pulling records from your dev database. Make sure you're ENV is set to the production environment: RAILS_ENV=production bundle exec rake sitemap:create and that you're able to connect to your production database.
I want to use this gem (sitemap_generator)
sitemap_generator
To create my sitemap xml file for my site.
So i create sitemap.rb inside config folder
Then i put this code inside
require 'rubygems'
require 'sitemap_generator'
SitemapGenerator::Sitemap.default_host = 'https://xxxx.com/'
SitemapGenerator::Sitemap.create do
# add '/home', :changefreq => 'daily', :priority => 0.9
# add '/contact_us', :changefreq => 'weekly'
add '/'
add '/signup'
add '/login'
Activity.find_each do |activity|
add activity_show_path(activity.id), :lastmod => activity.created_at
end
end
SitemapGenerator::Sitemap.ping_search_engines # Not needed if you use the rake tasks
But when i run
ruby config/sitemap.rb
I always got this
uninitialized constant Activity (NameError)
So how can i fixed this
(I guess the problem from the model)
Thanks!
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)
I have 2 cucumber scenarios that simulate paperclip image upload. I want to remove those folders again once scenarios are complete.
I have the following attachment folder structure:
:url => "/system/:attachment/:listing_id/:id/:style_:filename"
Paperclip automatically deletes the :id/:style_:filename folder but not the parent folder.
I have a the following in my listings controller (1 listing has many images) which works great to remove the image folder with the listing id when the listing is deleted. I need to simulate the same in Cucumber after the step is run.
def destroy
#listing = Listing.find(params[:id])
# if destroy was a success, remove the listing image folder
if #listing.destroy
end
require 'fileutils'
dir = Rails.root + '/system/photos/' + #listing.id.to_s()
FileUtils.rm_rf(dir)
respond_to do |format|
format.html { redirect_to(listings_url) }
format.xml { head :ok }
end
end
I could a) tell cucumber to delete the :listing_id folder name after running through the scenario or b) tell cucumber to delete the listing as the final step?
I've tried adding this to my cucumber env.rb file:
AfterStep('#paperclip') do
# This will only run before steps within scenarios tagged
# with #cucumis AND #sativus.
# delete folders that were created with paperclip during the test
require 'fileutils'
##listing.id = 55
#dir = Rails.root + '/system/photos/' + #listing.id.to_s()
dir = Rails.root + '/system/photos/55' # NOT WORKING
FileUtils.rm_rf(dir)
end
But that causes problems because 1) I don't know how to get the #listing.id from that scenario, and 2) even when I hardcode it (as above) it doesn't remove it.
Any thoughts?
Already a bit older, but as I just ran over the same issue myself here is what I did:
dir = Rails.root + 'images/'
dir.rmtree if dir.directory?
# or the short form, if you know the directory will be there
(Rails.root + 'images/').rmtree
So I guess the problem was your '/' at the beginning of the folder. At least for me it didn't work with that slash.
I would leave a comment, but don't have the points (or so I would assume) to do so.
There really is no reason that this shouldn't work. Have you confirmed that FileUtils.rm_rf(dir) does in fact remove the directory in the test environment?
You can test this in 'script/console test'.
You can hook into Cucumber's at_exit to remove any folders you like. I'm using the attached code in features/support/uploads_cleaner.rb.
# Removes uploaded files when all scenarios for the current test process
# are finished. Ready for parallel_tests, too.
require 'fileutils'
at_exit do
directory_name = "#{ Rails.env }#{ ENV['TEST_ENV_NUMBER'] }"
uploads_path = Rails.root.join('public/system', directory_name)
FileUtils.remove_dir(uploads_path) if uploads_path.directory?
end
Reposted from this makandra Card.
I'm trying to get a sinatra app as a subpath in my rails 3 app.
Specifically, the resque queuing system has a sinatra based web interface that I would like to have accessible through /resque on my usual rails app.
You can see the project here: http://github.com/defunkt/resque
I found some people talking about adding a rackup file and doing this sort of thing:
run Rack::URLMap.new( \
"/" => ActionController::Dispatcher.new,
"/resque" => Resque::Server.new
)
But I don't really know where to put that or how to make it run. My deployment is with passenger, but it would me nice to also have it running when I run 'rails server' too. Any suggestions?
--edit--
I've made some progress by putting the following in config/routes.rb:
match '/resque(/:page)', :to => Rack::URLMap.new("/resque" => Resque::Server.new)
Which seems to work pretty well, however it loses the public folder, (which is defined within the gem I guess), and as a result, there is no styling information, nor images.
You can setup any rack endpoint as a route in rails 3. This guide by wycats goes over what you are looking for and many of the other things you can do in rails3:
http://yehudakatz.com/2009/12/26/the-rails-3-router-rack-it-up/
For example:
class HomeApp < Sinatra::Base
get "/" do
"Hello World!"
end
end
Basecamp::Application.routes do
match "/home", :to => HomeApp
end
Yehuda (/Scott S)'s solution doesn't work for me with Rails 3.0.4 and Sinatra 1.2.1... setting :anchor => false in the matcher is the key:
# in routes.rb
match "/blog" => MySinatraBlogApp, :anchor => false
# Sinatra app
class MySinatraBlogApp < Sinatra::Base
# this now will match /blog/archives
get "/archives" do
"my old posts"
end
end
(answer c/o Michael Raidel - http://inductor.induktiv.at/blog/2010/05/23/mount-rack-apps-in-rails-3/)