【问题标题】:undefined method `escape' for URI:Module in Rails 7 with gravatar_image_urlRails 7 中带有 gravatar_image_url 的 URI:Module 的未定义方法“转义”
【发布时间】:2023-01-20 14:15:19
【问题描述】:

URI:Module 的未定义方法“转义”

  URI.escape(value, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
     ^^^^^^^
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
            <%= render "devise/shared/error_messages", resource: resource %>
            <div class="modal-body p-5 pt-0">
                <form class="">
                    <div class="form mb-3">
                        <div class="row">
                            <div class="col-sm-4">
                                <%if resource.avatar.attached? %>
                                <%= image_tag resource.avatar.variant(resize: "100x100!"), class: "rounded-circle" %>
                                <%else%>

                                <%= image_tag gravatar_image_url(current_user.email, size: 100), class: "rounded-circle" %>

                                <%end%>
                            </div>

问题在这里

<%= image_tag gravatar_image_url(current_user.email, size: 100), class: "rounded-circle" %>

尝试了一些解决转义的选项,但根本不起作用。不确定这是 gravatar_image_tag gem 问题还是我的设置存在一些问题。

【问题讨论】:

标签: ruby-on-rails


【解决方案1】:

URI#escape 已被弃用,后来被删除 - https://github.com/ruby/uri/commit/61c6a47ebf1f2726b60a2bbd70964d64e14b1f98

从提交:

# This method is obsolete and should not be used. Instead, use
# CGI.escape, URI.encode_www_form or URI.encode_www_form_component
# depending on your specific use case.

Ruby 3.0.0 以上的 URI#escape 不工作。

如弃用说明中所述,使用 CGI.escapeURI.encode_www_form

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多