Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Rails 4.0-基于路由的资源路径更改?_Ruby_Ruby On Rails 4_Routes - Fatal编程技术网

Ruby Rails 4.0-基于路由的资源路径更改?

Ruby Rails 4.0-基于路由的资源路径更改?,ruby,ruby-on-rails-4,routes,Ruby,Ruby On Rails 4,Routes,在我的application.rb文件中,我有以下内容: config.assets.paths'管理员#登录' 当我导航到localhost:3000/admin/sign_in时,我收到了一堆404错误。资产试图在以下位置加载: localhost:3000/admin/assets/… 为什么当我导航到自定义路由时,资源会尝试在/admin/assets处加载,但当导航到它们在/assets处加载的根路由时,资源会尝试在/assets处加载 编辑: 我的application.html.e

在我的
application.rb
文件中,我有以下内容:

config.assets.paths'管理员#登录'

当我导航到
localhost:3000/admin/sign_in
时,我收到了一堆404错误。资产试图在以下位置加载:

localhost:3000/admin/assets/…

为什么当我导航到自定义路由时,资源会尝试在
/admin/assets
处加载,但当导航到它们在
/assets
处加载的根路由时,资源会尝试在
/assets
处加载

编辑:

我的
application.html.erb
如下所示:

<!DOCTYPE html>
<html>
<head>
  <title>Website</title>
  <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
  <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
  <%= csrf_meta_tags %>
</head>
<body>

<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>

<%= yield %>

</body>
</html>

网站
正确%>
正确%>

编辑2:

我正在使用一个主题,我的html文件现在看起来都与此相似:

<link href='assets/images/meta_icons/favicon.ico' rel='shortcut icon' type='image/x-icon'>
    <link href='assets/images/meta_icons/apple-touch-icon.png' rel='apple-touch-icon-precomposed'>
    <link href='assets/images/meta_icons/apple-touch-icon-57x57.png' rel='apple-touch-icon-precomposed' sizes='57x57'>
    <link href='assets/images/meta_icons/apple-touch-icon-72x72.png' rel='apple-touch-icon-precomposed' sizes='72x72'>
    <link href='assets/images/meta_icons/apple-touch-icon-114x114.png' rel='apple-touch-icon-precomposed' sizes='114x114'>
    <link href='assets/images/meta_icons/apple-touch-icon-144x144.png' rel='apple-touch-icon-precomposed' sizes='144x144'>
    <!-- / START - page related stylesheets [optional] -->

    <!-- / END - page related stylesheets [optional] -->
    <!-- / bootstrap [required] -->
    <link href="assets/stylesheets/bootstrap/bootstrap.css" media="all" rel="stylesheet" type="text/css" />
    <!-- / theme file [required] -->
    <link href="assets/stylesheets/light-theme.css" media="all" id="color-settings-body-color" rel="stylesheet" type="text/css" />
    <!-- / coloring file [optional] (if you are going to use custom contrast color) -->
    <link href="assets/stylesheets/theme-colors.css" media="all" rel="stylesheet" type="text/css" />
    <!-- / demo file [not required!] -->
    <link href="assets/stylesheets/demo.css" media="all" rel="stylesheet" type="text/css" />
    <!--[if lt IE 9]>
      <script src="assets/javascripts/ie/html5shiv.js"
              type="text/javascript"></script>
      <script src="assets/javascripts/ie/respond.min.js"
              type="text/javascript"></script>
      <![endif]-->





<!-- / jquery [required] -->
    <script src="assets/javascripts/jquery/jquery.min.js" type="text/javascript"></script>
    <!-- / jquery mobile (for touch events) -->
    <script src="assets/javascripts/jquery/jquery.mobile.custom.min.js" type="text/javascript"></script>
    <!-- / jquery migrate (for compatibility with new jquery) [required] -->
    <script src="assets/javascripts/jquery/jquery-migrate.min.js" type="text/javascript"></script>
    <!-- / jquery ui -->
    <script src="assets/javascripts/jquery/jquery-ui.min.js" type="text/javascript"></script>
    <!-- / jQuery UI Touch Punch -->
    <script src="assets/javascripts/plugins/jquery_ui_touch_punch/jquery.ui.touch-punch.min.js" type="text/javascript"></script>
    <!-- / bootstrap [required] -->
    <script src="assets/javascripts/bootstrap/bootstrap.js" type="text/javascript"></script>
    <!-- / modernizr -->
    <script src="assets/javascripts/plugins/modernizr/modernizr.min.js" type="text/javascript"></script>
    <!-- / retina -->
    <script src="assets/javascripts/plugins/retina/retina.js" type="text/javascript"></script>
    <!-- / theme file [required] -->
    <script src="assets/javascripts/theme.js" type="text/javascript"></script>
    <!-- / demo file [not required!] -->
    <script src="assets/javascripts/demo.js" type="text/javascript"></script>
    <!-- / START - page related files and scripts [optional] -->
    <script src="assets/javascripts/plugins/validate/jquery.validate.min.js" type="text/javascript"></script>
    <script src="assets/javascripts/plugins/validate/additional-methods.js" type="text/javascript"></script>
    <!-- / END - page related files and scripts [optional] -->

尝试将文件从
.html
更改为
.html.erb
,并使用
样式表链接标签
来要求资产:


这应该可以为您解决问题。

我相信Rails在
/assets/image name.jpg
/assets/stylesheet name.css
/assets/application.js
和no9t
assets/images/meta_icons/apple touch icon.png
上提供资产服务,就像您写的那样


获取“admin/sign\u in”,它正在
views/admin/

中寻找sign\u in.html.erb模板。请显示布局中包含资产的部分(即您调用的位置)@DMKE我添加了我的application.html.erb,这是唯一提到的样式表链接标记代码。我还确认,如果您选择
get'sign\u in'
而不是
get'admin/sign\u in'
路径,问题就解决了。这很奇怪。您是否以任何其他方式(例如手动插入
)将样式表包括在其他任何地方?@DMKE我使用的是引导主题,我确信这与此有关。我编辑了我的文章,其中包含了一个示例,说明了当前所有必需资产的布局。