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.
Related
I've been trying to fix this for about two days but I'm getting no where. I'm trying to get the resque-web page to show but I keep running into the error
Sprockets::Rails::Helper::AssetNotPrecompiled in ResqueWeb::Overview#show
Message shown
ActionView::Template::Error (resque_web/plugins/resque_scheduler/application.css):
12: file_path = "#{p.name.underscore.downcase}/application.css"
13: if (Rails.application.assets && Rails.application.assets.find_asset(file_path)) ||
14: (Rails.application.assets_manifest && Rails.application.assets_manifest.assets[file_path])
15: stylesheet_link_tag "#{p.name.underscore.downcase}/application"
16: end
17: end.join("\n").html_safe
18: %>
what is being called from the stack
def raise_unless_precompiled_asset(path)
raise Helper::AssetNotPrecompiled.new(path) if #check_precompiled_asset && !precompiled?(path)
end
end
end
gem versions
resque (2.0.0)
resque-multi-job-forks (0.5.1)
resque-scheduler (4.4.0)
resque-web (0.0.12)
sprockets (4.0.2, 3.7.2)
sprockets-rails (3.2.2)
routes.rb
require "resque_web"
require 'resque-scheduler'
require 'resque/scheduler/server'
Rails.application.routes.draw do
mount ResqueWeb::Engine => "/resque_web"
root to: "pages#home"
.
.
.
end
Ideally it will be 'admin/resque_web' for production purposes.
I've tried this fix by "bitterloa" https://github.com/resque/resque-web/issues/106 because my file structure is set the same using webpacker
I've looked and the development.rb to check that debugging is false
I've recompiled my assets after destroying them using sprock-rails rails assets:clobber
Any ideas where I can look or if anyone else has run into this problem lend a hand please.
Run commands from terminal shows that resque is running and accepting schedule jobs from my scheduler.yml file I just can't get the css for it to work.
If you need any more info let me know.
Thanks
resque comes with a built-in server. You do not need resque-web and it seems it is not maintained (last commit was on 2018).
Let's try this:
gem 'resque', require: 'resque/server'
# routes.rb
mount Resque::Server.new, :at => "admin/resque"
Make sure you allow just admins to access to that page in production. For that you could read about Route Constraints to do something like:
constraints IsResqueAllowed do
mount Resque::Server.new, :at => "admin/resque"
end
class IsResqueAllowed
def self.matches?(request)
# use the request to do something
end
end
More information about securing the route here.
If you want to use resque-web then in order to fix this issue you will need to add in assets.rb:
Rails.application.config.assets.precompile += %w[idle lifebuoy poll rails working].map { |img| "resque_web/#{img}.png" }
Rails.application.config.assets.precompile += %w[resque_web/application.css]
Rails.application.config.assets.precompile += %w[resque_web/application.js]
Subsequently you will need to run: rake assets:precompile
And the issue should be fixed.
I am familiar with Rails but this is my first time uploading to production. I am able to successfully upload my app to AWS and deploy it. However, every time I do that, I have to ssh into my server and run the necessary rake tasks to clean up my models and fully prep my website. Is there a file like production.rb where you can write a script to be run on every production upload. For instance run all tests and rake tests ? Is there a simple example of a script someone. This is the example of my rake file.
Note: I am using AWS Beanstalk, super easy to deploy, just want to run some post production ready scripts.
This is the rake file I want to run commands of post deployment.
require "#{Rails.root}/app/helpers/application_helper"
include ApplicationHelper
namespace :db do
desc "Generate a new blog post markdown"
task new_article: :environment do
cp 'lib/assets/articles/template.md', "lib/assets/articles/NEW_ARTICLE#{Time.now.strftime("%s")}.md"
puts 'new article created!'
end
task populate: :environment do
Article.destroy_all
if User.count == 0
User.create!(name: "AJ", email: "aj#psychowarfare.com")
end
puts Dir.pwd
a = File.join("lib", "assets", "articles", "*.md")
Dir.glob(a).reject { |name| /.*(template|NEW_ARTICLE).*/ =~ name }.each do |file|
File.open(file, "r") do |f|
contents = f.read
mkdown = Metadown.render(contents)
md = mkdown.metadata
unrendered_content = contents.sub(/^---(\n|.)*---/, '')
#puts unrendered_content
article = Article.create!(title: md["title"],
content: markdown(unrendered_content),
header_image: md["header_image"],
published: md["published"],
useful_links: md["useful_links"],
people_mentioned: md["people_mentioned"],
written_at_date: md["written_at_date"],
timestamp: md["timestamp"],
embedded_link: md["embedded_link"],
user: User.first)
article.add_tag(md["tags"])
puts article.useful_links
puts article.people_mentioned
puts article.header_image
puts article.tags
end
end
puts "Article Count: #{Article.count}"
end
end
For post deployment, you can try the following way.
Create a file in .ebextensions/01_build.config
commands:
create_post_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_build_app.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
cd /var/app/current/app/
Your-Post-Deploy-Command1
Your-Post-Deploy-Command2
Your-Post-Deploy-Command3
What this config does is:
create the “post” directory if it doesn’t already exist (it won’t by
default) – ignore any errors (such as if the directory already
existed)
deploy the shell script with the appropriate permissions into the right directory
For more details look at the following references: Blog-Article & Stackoverflow-Question
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 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.
I have recently deployed my Ruby on Rails app from running it locally on my machine to a VPS server. The Administration section isn't working, with username and password. It works locally, but online, I can't get in to administer my user details. The rest of the app seems to be working ok, just not the Admin.
In my db/seeds.rb I have:
Admin.create(:email => "admin#admin.com", :password => "admin_password")
#unless Rails.env.production?
# 1000.times do
# Factory.create(:user)
# end
#end
categories_file = File.join(Rails.root, 'config', 'categories.txt')
if File.exists?(categories_file)
File.open(categories_file, 'r') do |f|
while category = f.gets
Category.create(:name => category)
end
end
end
Is there something I need to do to get it working correctly? Thanks.
Someone ran:
RAILS_ENV=production bundle exec rake db:seed
from the production instance (whatever that is) on the server, and now it's working.