【发布时间】:2018-01-31 10:28:14
【问题描述】:
我使用如下命令创建一个新应用程序(使用react webpack)
我用过 Rails 5.1.4
rails new news --database=postgresql --webpack=react
我有一些图像放在app/assets/images 中,所以在文件夹app/javascript/src/components/test.jsx 中,我想显示这个放在assets/images 中的images。
import React, { Component } from 'react'
import addBanner from 'images/addbanner_728x90_V1.jpg';
class Header extends Component {
render() {
return (
<header id="header">
<img src={addBanner} alt="" />
</header>
)
}
}
这是我的webpacker.yml
default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: ['app/assets']
当我运行rails server 时,图像没有显示在我的网站上。
这是在chrome 的debug console 上显示的错误。
GET http://localhost:3000/packs/_/assets/images/addbanner_728x90_V1-b8833c72a88a27dde49f4c9067bef50d.jpg net::ERR_BLOCKED_BY_CLIENT
如何显示此图像?
【问题讨论】:
标签: javascript ruby-on-rails reactjs webpack