小编Orl*_*lin的帖子

访问rails资产的相对路径

我被卡住了!xD我一直在研究Rails项目,但是在使用相对路径访问我的资产时遇到了问题.当我处理控制器和模型时,我的一个朋友正在研究html/css方面的事情.我的朋友最近给了我一批以下列方式构建的文件:

app/assets/images/*.jpg
app/assets/stylesheets/*.css
app/assets/javascripts/*.js
app/assets/fonts/*.* (+some more css files in here)
Run Code Online (Sandbox Code Playgroud)

在我的app/views/layouts目录中,我有一个名为final.html.erb的布局,用于我的整个webapp.我还有1页(html正文内容),我正在尝试使用名为final_page.html.erb的app/views/pages中的此布局进行渲染...必要的路由到位才能加载页面; 但是,它只加载final_page.html.erb的上下文(没有图像,样式或字体).当我进入控制台并键入"rails server"并访问localhost:3000时,页面显示...裸体lol.控制台输出以下内容:


Started GET "/" for 127.0.0.1 at 2012-07-28 21:15:02 -0700
Connecting to database specified by database.yml
Processing by PagesController#final_page as HTML
  Rendered pages/final_page.html.erb within layouts/final (8.4ms)
Completed 200 OK in 82ms (Views: 81.0ms | ActiveRecord: 0.0ms)


Started GET "/assets/stylesheets/style.css" for 127.0.0.1 at 2012-07-28 21:15:04 -0700

ActionController::RoutingError (No route matches [GET] "/assets/stylesheets/style.css"):
  actionpack (3.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.6) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.6) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.6) lib/rails/rack/logger.rb:16:in `call' …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails relative-path sprockets asset-pipeline

6
推荐指数
1
解决办法
2万
查看次数