[英]How to pass seeded image data into Rails views?
I seeded my Rails db with the following for Posts: title, description, body, and image. 我在Rails db的种子中添加了以下内容:标题,描述,正文和图像。 For image I used data in the assets. 对于图像,我使用了资产中的数据。 So for example in the seed file I have: 因此,例如,在种子文件中,我有:
post_image: '/images/main.image.jpg'
I'm able to hit all the other data in the views doing the typical: 我可以按典型方式查看视图中的所有其他数据:
<%= post.title %>
How do I pull in the image? 如何拉入图像? I've tried the following to no avail: 我尝试了以下无济于事:
Did I seed incorrectly or am I just using the wrong helper to get the image? 我播种不正确还是使用了错误的帮助程序来获取图像?
Yeah I seeded incorrectly. 是的,我播种不正确。 Image_tag will hit images under the asset pipeline. Image_tag将命中资产管道下的图像。 Did a db:reset after I fixed the seed file to just be: post_image: 'main.image.jpg'. 在将种子文件固定为:post_image:'main.image.jpg'之后,是否执行了db:reset。 Correct code is: 正确的代码是:
<%= image_tag post.post_image %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.