ruby-on-rails rails_blob_path主机:只有_path:true返回相同的?

x33g5p2x  于 2023-08-08  发布在  Ruby
关注(0)|答案(1)|浏览(108)

我正在研究如何使用Rails.application.routes.url_helpers.rails_blob_path
我有一堂课

has_one_attached :logo

字符串
然后我就做了

Rails.application.routes.url_helpers.rails_blob_path(record.logo)


它给了我一个错误

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true (ArgumentError)


好吧我试试

Rails.application.routes.url_helpers.rails_blob_path(obi.logo, host: "wwww.example.com" )
=> "/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBEUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--5d977f0c66fecd8c8474355813aad9490fcdfbf2/picture.png"


结果和

Rails.application.routes.url_helpers.rails_blob_path(obi.logo, only_path: true )
=> "/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBEUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--5d977f0c66fecd8c8474355813aad9490fcdfbf2/picture.png"


当使用host:参数时,我希望它将“www.example.com”附加到输出中。为什么它的结果与only_path: true相同?

mnemlml8

mnemlml81#

使用主机时:参数我希望它将“www.example.com“附加到输出中。为什么它的结果与only_path相同:真的吗
在Rails中,有两种类型的URL帮助器--pathurl
后缀_path--相对URL路径
后缀为_url--绝对URL

Rails.application.routes.url_helpers.rails_blob_url(obi.logo, host: "https://www.example.com")

# => "https://www.example.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBEUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--5d977f0c66fecd8c8474355813aad9490fcdfbf2/picture.png"

字符串

相关问题