【发布时间】:2017-07-25 11:49:51
【问题描述】:
我已将devise :confirmable 添加到我的模型中并创建了一个 before_create 以跳过确认。
before_create :skip_confirmation
def skip_confirmation
self.skip_confirmation!
end
我有一个名为 store_mailer.rb 的邮件程序以及适当的视图 app/views/stores/mailer/confirmation_introctions.html.erb 以发送确认电子邮件。
class StoreMailer < Devise::Mailer
helper :application # gives access to all helpers defined within `application_helper`.
include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
default template_path: 'store/mailer' # to make sure that your mailer uses the devise views
end
confirmation_introctions.html.erb
<h2>Resend confirmation instructions</h2>
<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
</div>
<div class="actions">
<%= f.submit "Resend confirmation instructions" %>
</div>
<% end %>
<%= render "stores/shared/links" %>
我正在尝试使用以下内容发送确认电子邮件:
StoreMailer.confirmation_instructions(@store).deliver
但它返回以下错误:ArgumentError in TransactionsController#create
wrong number of arguments (given 1, expected 2..3)
有什么想法可能是错的吗?
更新 1
transaction_controller.rb
def create
nonce_from_the_client = params['payment_method_nonce']
@result = Braintree::Customer.create(
first_name: params['first_name'],
last_name: params['last_name'],
:payment_method_nonce => nonce_from_the_client
)
if @result.success?
puts @result.customer.id
puts @result.customer.payment_methods[0].token
StoreMailer.confirmation_instructions(@store).deliver
redirect_to showcase_index_path, notice: 'Subscribed, please check your inbox for confirmation'
else
redirect_back( fallback_location: (request.referer || root_path),
notice: "Something went wrong while processing your transaction. Please try again!")
end
end
【问题讨论】:
-
TransactionsController#create中有什么内容? -
这是我将
StoreMailer.confirmation_instructions(@store).deliver放入其中的另一种方法 -
也分享该代码
-
请检查更新1
标签: ruby-on-rails ruby ruby-on-rails-4 devise devise-confirmable