assets目录有关问题


        assets目录问题<br />

跟着应用Rails进行敏捷Web开发(第3版) 做例子。


   书上的例子中css文件是放在public\stylesheets 中的,用这个方法在开发模式下出错,找不到css文件

根据提示知道html页面找的是assets目录中的文件。

   

    在开发模式下不能自动编译到这个目录下吗?大家在开发中直接把css等文件放到assets目录中?

ruby 程序开发 Ruby语言基础

haha王 10 years, 6 months ago

The old rails, the css file, javascript & image are put in the public folder.

In the new rails about rails3.x.x, these files are put in the app\assets. And you can set assets path in the config/application.rb. Like below:

#Additional (fully qualified) paths can be added to the pipeline in config/application.rb.

config.assets.paths $amp;<amp> </amp> <amp>
rails will search the path app\assets\javascripts, app\assets\stylesheets, app\assets\images and app\assets\components(This folder was added by you.) if not find the target file. rails will search vendor\assets folder.
But this for development mode, after you deliver to production. In fact, these assets were in the public folder. You need to use 'rake assets:precompile' to compile these assets when you deploy.
Of course, you can also disable asset pipeline in the config/application.rb
config.assets.enabled = true
The detail you can see 
Hope this can help you. </amp>

邪恶D少年 answered 10 years, 6 months ago

rails3和rails4在开发模式下,rails是直接读assets文件夹下的css文件,生产环境下则是将所有css文件打包编译成一个css文件,放在public目录下。

第三版是rails2的教程,建议看 ,另外推荐一个rails学习资料网站

伯爵大人的仆从 answered 10 years, 6 months ago

Your Answer