我在Rails 7项目中有这个Mailer
:
# app/mailers/quote_mailer.rb
class QuoteMailer < ApplicationMailer
def quote_mail(quote)
@quote = quote
@user = quote.user
@client = quote.client
@account = quote.account
I18n.with_locale(@quote.locale) do
mail(
:from => @user.email,
:to => @client.email,
:subject => "New Quote"
)
end
end
end
# app/views/mailer/quote_mail.text.erb
Dear <= @client.name %>
Please click here to download your Quote:
<%= quote_download_url(@quote.token, :namespace => @account.namespace) %>
Best regards
<%= @user.name %>
# config/routes.rb
Rails.application.routes.draw do
scope ':locale', :locale => /#{I18n.available_locales.join("|")}/ do
scope ':namespace' do
resources :quote_downloads, :only => [:show]
end
end
end
不幸的是,电子邮件中的链接无法构建并抛出错误:
ActionView::Template::Error(No route matches {:action=>“show”,:controller=>“quote_downloads”,:locale=>“VmKHoRSx79AEatcoHtPz8uun”,:namespace=>“volkswagen”},missing required keys:[:id],可能不匹配的约束:[:locale]
似乎我的namespace
参数混淆了Rails。
如何解决这个问题?
1条答案
按热度按时间w51jfk4q1#
我不希望
I18n.with_locale
在URL中设置locale
,除非locale
被配置为默认URL选项。我只希望它能改变呈现的电子邮件的区域设置。但是你可以像这样在你的邮件中手动传递它:
app/views/mailer/quote_mail.text.erb
字符串