开发者

rails assets path

开发者 https://www.devze.com 2023-03-24 09:38 出处:网络
I have in <link href=\"/assets/application.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />

I have in

  <link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" /> 
  <script src="/assets/application.js" type="text/javascript"></script> 

but when I go to http://localhost:3000/assets/application.css

Routing Error

No route matches [GET] "/assets/application.开发者_StackOverflow中文版css"

P.S. Rails 3.1.0.rc4, ruby 1.8.7


Seems Sprockets / Rails 3.1 were acting up for me w/ ruby 1.9.2-p180 ... updating to Ruby-1.9.2-p290 seemed to stop the issue.

Maybe not related to your issue... but useful for anyone else having that issue using those versions of Rails & Ruby.


I found that I had something similar going on after updating to Rails 3.1 this evening. I was working on a project that didn't use ActiveRecord, so I had a modified my application.rb to exclude it. The line that usually reads require 'rails/all' to only include the parts I needed, like this:

require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"

This list has changed in Rails 3.1 to include Sprockets, the core component to making the asset pipeline work. I got the asset pipeline serving the serving content as expected by adding this line to the bottom of the list:

require "sprockets/railtie"

After restarting, /assets/application.js and other assets began working as expected.

Note: if you have a custom setup like this, be sure to open the railties gem and look at the contents of lib/rails/all.rb which may have changed (as in this case).


Your scripts and styles will be loaded from the public folder. Drop the assets folder under public and you should be good to go.


In the application layout file, if you have

<%= stylesheet_link_tag "/assets/application" %>

which gives

No route matches [GET] "/assets/application.css"

TRY changing it to

<%= stylesheet_link_tag "application" %>


I had to add the following line in application.rb:

    config.assets.enabled = true

in bottom of class Application < Rails::Application

0

精彩评论

暂无评论...
验证码 换一张
取 消