- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将 Rails 6 应用程序部署到子文件夹 (/dictionnaire-app) 中。我设置了config.relative_url_root = "/dictionnaire-app"
在 application.rb 中,还根据 the documentation 添加了 ENV 变量.
但是,如果 Assets 正确呈现,则会生成带有 link_to
的链接。方法不会相应更新。
我阅读了许多与此问题相关的问题,并尝试在我的 routes.rb 文件中创建一个范围,如下 these instructions .
Rails.application.routes.draw do
mount ForestLiana::Engine => '/forest'
root to: "home#index"
scope 'dictionnaire-app' do
resources :words, path: "definition", param: :slug
post '/search', to: 'words#search'
get '/recherche', to: 'words#search_page'
get '/:letter', to: 'words#alphabet_page', param: :letter, as: "alphabetic_page"
end
end
不幸的是,该应用程序抛出一个错误,指出此 URL 的页面不存在:
https://www.lalanguefrancaise.com/dictionnaire-app/definition/rameal
最佳答案
我以前没有尝试过,但我可以想象这样的事情可能会奏效:
# config/routes.rb
if Rails.application.config.relative_url_root == "/dictionnaire-app"
extend DictionaryRoutes
else
scope 'dictionnaire-app' do
extend DictionaryRoutes
end
# config/routes/dictionary_routes.rb
module DictionaryRoutes
def self.extended(router)
router.instance_exec do
resources :words, path: "definition", param: :slug
post '/search', to: 'words#search'
get '/recherche', to: 'words#search_page'
get '/:letter', to: 'words#alphabet_page', param: :letter, as: "alphabetic_page"
end
end
end
通常,您不希望在路由中使用 if-else,但在这种情况下,您实际上是在为应用动态定义路由是否存在。可能需要更多自定义才能使其正常工作。假设您试图允许
/search
因为你的路线不是
/dictionnaire-app/search
(或者是导致问题的原因)。
关于ruby-on-rails - Rails 6 relative_url_root 不适用于子目录中的部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63228898/
相当于 relative_url_root在 ActionMailer 中? 我试过在 default_url_options 中设置它,但它会在查询字符串中附加参数。 添加 :skip_relati
我正在将 Rails 6 应用程序部署到子文件夹 (/dictionnaire-app) 中。我设置了config.relative_url_root = "/dictionnaire-app"在 a
我目前正在使用 Ruby on Rails 3.2.8 并且在 config/routes.rb 中有这个重定向: root :to => redirect("/home/index.html") 在
我试着关注 this tutorial在 tomcat 上部署我的 jruby 应用程序,但它总是以: --- Backtrace NoMethodError: undefined metho
我一直致力于从 2.3.11 升级到 Rails 3.1。需要清除的主要障碍之一是向 Assets 管道的转换。在这个过程中,我决定将我的 css 转换为 sass (scss)。在 rails 3.
我正在将 Rails 2.3.18 升级到 3.2.x,我在这组 Controller 测试中遇到了问题: 错误: /actionpack-3.2.12/lib/action_controller/t
我是一名优秀的程序员,十分优秀!