我一直在使用以下指南中的子模块的博客应用程序(octopress)开发应用程序:
http://www.nickhammond.com/setting-octopress-jekyll-blog-rails-application/
它有点过时但除了必须改变一些宝石似乎工作正常。该指南建议在主要的父app应用程序目录中有一个名为“Blog”的文件夹,其中较小的应用程序存在。在这里,我被告知要更改config.ru文件,并将其重命名为run.rb.该文件如下:
/blog/run.rb
require 'bundler/setup'
require 'sinatra/base'
# The project root directory
$root = ::File.dirname(__FILE__)
class Blog < Sinatra::Base
get(/.+/) do
send_sinatra_file(request.path) {404}
end
not_found do
send_file(File.join(File.dirname(__FILE__), 'public', '404.html'), {:status => 404})
end
def send_sinatra_file(path, &missing_file_block)
file_path = File.join(File.dirname(__FILE__), 'public', path)
file_path = File.join(file_path, 'index.html') unless file_path =~ /\.[a-z]+$/i
File.exist?(file_path) ? send_file(file_path) : missing_file_block.call
end
end
我的父应用程序中的我的config.ru文件如下:
/config.ru
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
require './blog/run'
# Action Cable requires that all classes are loaded in advance
Rails.application.eager_load!
map '/' do
run Rails.application
end
map '/blog' do
run Blog
end
当我访问localhost:3000 / blog时,我没有找到路由未找到错误,但是收到:
This localhost page can’t be found
No web page was found for the web address: http://localhost:3000/blog
任何有关如何正确设置我的config.ru文件的帮助将非常感谢,提前感谢。
答案 0 :(得分:0)
请尝试移动
require '/blog/run'
map '/blog' do
run Blog
end
到routes.rb,看看是否有帮助。
更新:(最后它说要将你的config.ru更改为此内容。)
require ::File.expand_path('../config/environment', __FILE__)
require './blog/run' # Require the run.rb file that we created earlier which has the Rack setup for the blog
map '/' do # By default we want everything to hit our Rails application
run Rails::Application
end
map '/blog' do # Anything at blog/ and beyond will then hit the blog
run Blog
end
请试一试。