Я пытаюсь сгенерировать карту сайта автоматически, используя гем sitemap_generator. Я попытался добавить действие show
, так как начал получать ошибку. Первоначально он был пустым ..
Ниже следует мой контроллер сообщений :
class PostsController < ApplicationController
before_filter :authorize, only: [:edit, :update, :new, :create, :destroy]
before_filter :find_post, only: [:show, :edit, :update, :destroy]
def index
@posts = Post.order("created_at DESC").page(params[:page]).per(9)
respond_to do |format|
format.html
format.rss { render :layout =>false }
end
end
def show
@posts = Post.all
end
def new
@post = Post.new
end
def create
@post = Post.new(post_params)
if @post.save
redirect_to posts_url
else
render 'new'
end
end
def edit
end
def update
if @post.update_attributes(post_params)
redirect_to post_url(@post), notice: "#{@post.title} Updated"
else
render 'edit'
end
end
def destroy
@post.destroy
redirect_to posts_url, notice: "#{@post.title} Deleted"
end
private
def post_params
params.require(:post).permit(:title, :contents, :author_id, :approved, :summary, :preview_image_id, :category, :social_title, :blog_title)
end
def find_post
@post = Post.friendly.find(params[:id])
# If an old id or a numeric id was used to find the record, then
# the request path will not match the post_path, and we should do
# a 301 redirect that uses the current friendly id.
if params[:action] == 'show' && request.path != post_path(@post)
return redirect_to @post, :status => :moved_permanently
end
end
end
rout.rb
Rails.application.routes.draw do
root to: "home#index"
resources :posts do
resources :comments
end
end
sitemap.rb
Post.friendly.find_each do |post|
add post_url(post), :lastmod => post.created_at
end
Я пробовал как с «дружественным», так и без «дружественного».
и при запуске rake sitemap:refresh
я получаю следующую ошибку Ubuntu: ~ / environment / site (master) $ rake карта сайта: refre sh
In '/home/ubuntu/environment/site/public/':
Post Load (0.6ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC LIMIT 1000
rake aborted!
ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"posts", :format=>nil, :id=>nil, :locale=>#<Post id: 1, title: "4 Tips For Managing Your Maintenance Team", contents: "<p>Maintenance teams are a special kind of problem...", approved: nil, created_at: "2020-03-30 16:17:28", updated_at: "2020-05-04 17:07:30", url: nil, blog_title: "4 Tips For Managing Your Maintenance Team">} missing required keys: [:id]