Rails ERB查看语法问题

ran*_*its 0 ruby ruby-on-rails actionview

我显然无法在这里得到正确的语法:

<table width="100%" border="0" cellspacing="0" cellpadding="20" background="<%= #{Rails.root}/app/assets/images/image.png %>">
Run Code Online (Sandbox Code Playgroud)

这样做的恰当方法是什么?

Tom*_*kes 5

Rails提供资产助手来获取图像文件的路径,并且与资产管道一起使用,并在您更改asset_host以使用CDN时自动工作.

<table width="100%" border="0" cellspacing="0" cellpadding="20" background="<%= image_path('image.png') %>">
Run Code Online (Sandbox Code Playgroud)

这是资产助手的文档