{"id":375,"date":"2012-01-17T14:06:10","date_gmt":"2012-01-17T06:06:10","guid":{"rendered":"http:\/\/www.whitetrefoil.com\/blog\/?p=375"},"modified":"2012-01-17T14:06:10","modified_gmt":"2012-01-17T06:06:10","slug":"%e8%ae%a9-rails-3-1-%e9%bb%98%e8%ae%a4%e4%bd%bf%e7%94%a8sass","status":"publish","type":"post","link":"https:\/\/www.whitetrefoil.com\/blog\/?p=375","title":{"rendered":"\u8ba9 Rails 3.1 \u9ed8\u8ba4\u4f7f\u7528Sass"},"content":{"rendered":"<p>\u56e0\u4e3a\u6bd4\u8d77\u7528\u7b26\u53f7\uff08\u5927\u62ec\u53f7\uff09\u63a7\u5236\u7684\u4ee3\u7801\u5c42\u6b21\uff0c\u66f4\u559c\u6b22\u6e05\u6670\u7684\u7f29\u8fdb\u5f0f\u5c42\u6b21\uff0c\u56e0\u6b64\u60f3\u628aRails\u9ed8\u8ba4\u7684SCSS\u6539\u6210SASS\uff0c\u5e0c\u671b\u901a\u8fc7\u8bf8\u5982 <code>rails g scaffold sth<\/code> \u751f\u6210\u51fa\u6765\u7684\u6837\u5f0f\u6587\u4ef6\u662fSass\u683c\u5f0f\u800c\u975eScss\u683c\u5f0f\u3002<\/p>\n<p>\u5728Google\u4e0a\u594b\u6597\u4e862\u4e2a\u5c0f\u65f6\uff0c\u9664\u4e86\u5728Stackflow\u4e0a\u627e\u5230\u4e00\u7bc7\u6587\u8ba9\u6211\u8fd8\u7565\u53d7\u542f\u53d1\u5916\uff08\u4f46\u8fd9\u7bc7\u6587\u4e2d\u8bb8\u591a\u4eba\u63d0\u51fa\u4e86\u8bb8\u591a\u79cd\u4e0d\u540c\u7684\u89e3\u51b3\u65b9\u6cd5\uff0c\u4e0d\u77e5\u4e3a\u4f55\u6211\u7528\u4e0b\u6765\u5c45\u7136\u5168\u90fd\u5931\u8d25\u4e86\uff09\uff0c\u5176\u4ed6\u7684\u51e0\u4e4e\u5f88\u96be\u627e\u5230\u3002<\/p>\n<p>\u7136\u540e\u6211\u5f00\u59cb\u8bfbrailties\u7684\u6e90\u7801\u2026\u2026\u7814\u7a76\u4e86\u534a\u5929generator\uff0c\u4e00\u65e0\u6240\u83b7\u2026\u2026\u6700\u540e\u90fd\u627e\u5230base.rb\u91cc\u53bb\u4e86\u3002\u6b64\u65f6\u6211\u5f00\u59cb\u610f\u8bc6\u5230\u53ef\u80fd\u65b9\u5411\u53d1\u751f\u4e86\u9519\u8bef\uff0c\u8f6c\u800c\u5f80\u66f4\u9ad8\u5c42\u7684\u65b9\u5411\u5bfb\u627e\uff0c\u6700\u540e\u7ec8\u4e8e\u5728sass-rails\/lib\/sass\/railtie.rb\u4e2d\u627e\u5230\u4e86<\/p>\n<p><code><\/p>\n<pre lang=\"ruby\">config.sass.preferred_syntax = :scss<\/pre>\n<p><\/code><\/p>\n<p>\u8fd9\u884c\u4ee3\u7801\u8ddfStackflow\u7f51\u7ad9\u4e0a\u67d0\u4eba\u63d0\u51fa\u7684\u529e\u6cd5\u76f8\u5dee\u65e0\u51e0\uff0c\u4e8e\u662f\u6309\u7167\u4ed6\u7684\u65b9\u6cd5\u653e\u5165\u6211\u7684rails\u5e94\u7528\u7684\/config\/application.rb\u4e2d\uff0c\u5c31\u5728Application\u7c7b\u4e2d\uff0c\u8ddf\u5728\u5176\u4ed6config.xxx\u540e\u9762\uff0c\u628a:scss\u6539\u6210:sass\uff0c\u7136\u540e\u8fd0\u884c<code>rails g scaffold orz<\/code>\uff0c\u679c\u7136\u89c1\u5230invoke sass\uff0c\u72c2\u559c\uff5e<\/p>\n<p><code><\/p>\n<pre lang=\"ruby\">require File.expand_path('..\/boot', __FILE__)\n\nrequire 'rails\/all'\n\nif defined?(Bundler)\n  Bundler.require(*Rails.groups(:assets => %w(development test)))\nend\n\nmodule MyApplicationName\n  class Application < Rails::Application\n    config.encoding = \"utf-8\"\n    config.filter_parameters += [:password]\n    config.assets.enabled = true\n    config.assets.version = '1.0'\n    config.sass.preferred_syntax = :sass\n  end\nend\n<\/pre>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u56e0\u4e3a\u6bd4\u8d77\u7528\u7b26\u53f7\uff08\u5927\u62ec\u53f7\uff09\u63a7\u5236\u7684\u4ee3\u7801\u5c42\u6b21\uff0c\u66f4\u559c\u6b22\u6e05\u6670\u7684\u7f29\u8fdb\u5f0f\u5c42\u6b21\uff0c\u56e0\u6b64\u60f3\u628aRails\u9ed8\u8ba4\u7684SCSS\u6539\u6210SASS\uff0c\u5e0c\u671b\u901a\u8fc7\u8bf8\u5982 <code>rails g scaffold sth<\/code> \u751f\u6210\u51fa\u6765\u7684\u6837\u5f0f\u6587\u4ef6\u662fSass\u683c\u5f0f\u800c\u975eScss\u683c\u5f0f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[25,40,52,55,213,58,59,61,66],"_links":{"self":[{"href":"https:\/\/www.whitetrefoil.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/375"}],"collection":[{"href":"https:\/\/www.whitetrefoil.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.whitetrefoil.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.whitetrefoil.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.whitetrefoil.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=375"}],"version-history":[{"count":0,"href":"https:\/\/www.whitetrefoil.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/375\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.whitetrefoil.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.whitetrefoil.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.whitetrefoil.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}