gpt4 book ai didi

ruby-on-rails - Rails 5 中的 RuntimeError 无法修改卡住的字符串

转载 作者:数据小太阳 更新时间:2023-10-29 07:58:55 32 4
gpt4 key购买 nike

我不明白为什么我的应用程序会出现“无法修改卡住的字符串”错误。

我正在尝试预览我在 tests/mailers/previews/user_mailer_preview.rb 中创建的邮件程序

我的邮件预览类如下:

class UserMailerPreview < ActionMailer::Preview

# Preview this email at http://localhost:3000/rails/mailers/user_mailer/account_activation
def account_activation
user = User.first
user.activation_token = User.new_token
UserMailer.account_activation(user)
end

使用的 UserMailer 类方法:

class UserMailer < ApplicationMailer
def account_activation(user)
@user = user
mail to: user.email, subject: "Mock Twitter App account activation"
end

User.rb 模型:

class User < ApplicationRecord
attr_accessor :remember_token, :activation_token
.
.
# Creates randonly generated token
def self.new_token
SecureRandom.urlsafe_base64
end

我正在尝试预览的简单邮件程序位于 views/user_mailer/account_activation.html/erb

Hi <%= @user.name %>,

<p>
Welcome to the Mock Twitter App! Click the link below to active your account:
</p>
<%= link_to "Activate account", edit_account_activation_url(@user.activation_token, email: @user.email) %>

这是服务器日志:

Started GET "/rails/mailers/user_mailer/account_activation" for ::1 at 2016-07-23 19:18:31 -0500
Processing by Rails::MailersController#preview as HTML
Parameters: {"internal"=>true, "path"=>"user_mailer/account_activation"}
User Load (0.9ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? [["LIMIT", 1]]
Rendering user_mailer/account_activation.html.erb within layouts/mailer
Rendered user_mailer/account_activation.html.erb within layouts/mailer (0.8ms)
Rendering user_mailer/account_activation.text.erb within layouts/mailer
Rendered user_mailer/account_activation.text.erb within layouts/mailer (0.5ms)
UserMailer#account_activation: processed outbound mail in 22.3ms
Completed 500 Internal Server Error in 62ms (ActiveRecord: 2.8ms)



RuntimeError (can't modify frozen String):

actionmailer (5.0.0) lib/action_mailer/inline_preview_interceptor.rb:29:in `gsub!'
actionmailer (5.0.0) lib/action_mailer/inline_preview_interceptor.rb:29:in `transform!'
actionmailer (5.0.0) lib/action_mailer/inline_preview_interceptor.rb:19:in `previewing_email'
actionmailer (5.0.0) lib/action_mailer/preview.rb:113:in `block in inform_preview_interceptors'
actionmailer (5.0.0) lib/action_mailer/preview.rb:112:in `each'
actionmailer (5.0.0) lib/action_mailer/preview.rb:112:in `inform_preview_interceptors'
actionmailer (5.0.0) lib/action_mailer/preview.rb:67:in `call'
railties (5.0.0) lib/rails/mailers_controller.rb:22:in `preview'
actionpack (5.0.0) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.0.0) lib/abstract_controller/base.rb:188:in `process_action'
actionpack (5.0.0) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.0.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.0.0) lib/active_support/callbacks.rb:126:in `call'
activesupport (5.0.0) lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
activesupport (5.0.0) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.0) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
activesupport (5.0.0) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
activesupport (5.0.0) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.0.0) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.0.0) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.0.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (5.0.0) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.0.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (5.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.0.0) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
activerecord (5.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (5.0.0) lib/abstract_controller/base.rb:126:in `process'
actionview (5.0.0) lib/action_view/rendering.rb:30:in `process'
actionpack (5.0.0) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (5.0.0) lib/action_controller/metal.rb:262:in `dispatch'
actionpack (5.0.0) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (5.0.0) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (5.0.0) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.0) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.0) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.0) lib/action_dispatch/routing/route_set.rb:725:in `call'
rack (2.0.1) lib/rack/etag.rb:25:in `call'
rack (2.0.1) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.1) lib/rack/head.rb:12:in `call'
rack (2.0.1) lib/rack/session/abstract/id.rb:222:in `context'
rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.0.0) lib/active_record/migration.rb:552:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.0) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.0) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.0) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.0) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
web-console (3.1.1) lib/web_console/middleware.rb:131:in `call_app'
web-console (3.1.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.1.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.1.1) lib/web_console/middleware.rb:18:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.0) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.0) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.0) lib/active_support/tagged_logging.rb:70:in `block in tagged'
activesupport (5.0.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.0) lib/active_support/tagged_logging.rb:70:in `tagged'
railties (5.0.0) lib/rails/rack/logger.rb:24:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.1) lib/rack/method_override.rb:22:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
railties (5.0.0) lib/rails/engine.rb:522:in `call'
puma (3.4.0) lib/puma/configuration.rb:224:in `call'
puma (3.4.0) lib/puma/server.rb:569:in `handle_request'
puma (3.4.0) lib/puma/server.rb:406:in `process_client'
puma (3.4.0) lib/puma/server.rb:271:in `block in run'
puma (3.4.0) lib/puma/thread_pool.rb:114:in `block in spawn_thread'

我已经在网上搜索了一段时间,但似乎无法弄清楚为什么会出现此错误。我认为 rails MailersController 正在尝试更改 activation_token?

任何见解将不胜感激。

最佳答案

在您的邮件中添加正文。

 def account_activation(user)
@user = user
mail(to: user.email, subject: "Mock Twitter App account activation", body: "meow")
end

如果 body 为 nil 则它被“卡住”。

关于ruby-on-rails - Rails 5 中的 RuntimeError 无法修改卡住的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38547496/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com