How to display image pointed by URL in Rails

后端 未结 4 1009
独厮守ぢ
独厮守ぢ 2021-02-13 16:58

I have a image here http://power.itp.ac.cn/~jmyang/funny/fun4.jpg and I want to display it in my Rails site. How should i do that?

相关标签:
4条回答
  • You can also use the action view image_tag helper:

    <%= image_tag 'http://power.itp.ac.cn/~jmyang/funny/fun4.jpg' %>
    

    Alternatively you can just use the regular HTML tags:

    ERB:

    <img src="http://power.itp.ac.cn/~jmyang/funny/fun4.jpg">
    

    Haml:

    %img{ src: "http://power.itp.ac.cn/~jmyang/funny/fun4.jpg" }
    

    Slim:

    img src="http://power.itp.ac.cn/~jmyang/funny/fun4.jpg"
    
    0 讨论(0)
  • 2021-02-13 17:20

    Put the URL into an img tag inside the view for the page that should display the image.

    0 讨论(0)
  • 2021-02-13 17:20

    Tested and worked.

    <img src="http://power.itp.ac.cn/~jmyang/funny/fun4.jpg", width="500" , height="400"> </img>
    
    0 讨论(0)
  • 2021-02-13 17:25

    <%= link_to image_tag post.image %>

    0 讨论(0)
提交回复
热议问题