我在使用 Ruby on Rails Webpacker 在视图中包含图像时遇到问题。当我尝试使用 html img 标签和 asset_pack_path 在我的视图中插入图像时,出现错误。我的图像位于app/javascript/images/logo.png
. 根据 webpacker 文档,我应该将 /media/ 附加到文件中,但这无济于事。我尝试了不同的路径,但仍然无法正常工作。我认为 webpacker 不会编译我的图像。
Webpacker::Manifest::MissingEntryError in Home#index
Showing app/views/layouts/application.html.haml where line #14 raised:
Webpacker can't find media/logo.png in public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack …
Run Code Online (Sandbox Code Playgroud) 我对 Rails API 应用程序主动存储有疑问。我有 React 从我想上传文件的地方。
import React from "react";
import {DirectUpload} from "activestorage";
class SignIn extends React.Component {
constructor(props) {
super(props);
this.state = {
file: null
};
this.handleFileChange = this.handleFileChange.bind(this);
this.handleFileSubmit = this.handleFileSubmit.bind(this);
}
handleFileChange(e){
this.setState({file: e.target.files[0]})
}
handleFileSubmit(){
const upload = new DirectUpload(this.state.file, "/rails/active_storage/direct_uploads");
upload.create((error, blob) => {
if(error){
console.log(error)
} else {
console.log(blob)
}
})
}
render() {
return (
<React.Fragment>
<Form>
<Form.Item>
<Input type="file" onChange={this.handleFileChange}/>
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit">
Register
</Button>
</Form.Item>
</Form>
</React.Fragment>
); …
Run Code Online (Sandbox Code Playgroud) 我正在寻找解决方案如何生成16位,65536元素查找表来计算设置位.我知道生成8位表我可以使用:
static const unsigned char BitsSetTable256[256] =
{
# define B2(n) n, n+1, n+1, n+2
# define B4(n) B2(n), B2(n+1), B2(n+1), B2(n+2)
# define B6(n) B4(n), B4(n+1), B4(n+1), B4(n+2)
B6(0), B6(1), B6(1), B6(2)
};
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在16位中做到这一点