0

devise :confirmableをモデルに追加し、before_createを作成して確認をスキップします。後で手動で確認メールを送信する

before_create :skip_confirmation 

def skip_confirmation 
    self.skip_confirmation! 
end 

私は確認のメールを送信するための適切な景色アプリ/ビュー/店舗/メーラー/ confirmation_instroctions.html.erbとともにメーラーという名前store_mailer.rbを持っています。

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_instroctions.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_controlller.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 
+0

'TransactionsController#create'には何がありますか? 'StoreMailer:私は' StoreMailer.confirmation_instructionsを配置することだ –

+0

そのもう一つの方法は、(@store)は.deliver'そのコードも – Theopap

+0

シェアの内側に、私はすでにこれを試してみました。 'check_instructions(@store、token).deliver' ...エラーを返します。'未定義のローカル変数またはメソッドトークン ' – Sajin

答えて

0

confirmation_instructionsDevise::Mailerで定義された方法(あなたのStoreMailerクラスのスーパークラス)です。
herehereのように、2つの必須引数と1つのオプションを受け入れます。

引数を1つだけ渡してメソッドを呼び出すとします。
は、次のように、あまりにも第二引数(token)に合格する必要があります。

def create 
    # ... 

    # Note: I'm not sure this is the token you really need. 
    # It's your responsibility check if it's correct. 
    token = @result.customer.payment_methods.first.token 
    StoreMailer.confirmation_instructions(@store, token).deliver 

    # ... 
end 
+0

感謝を確認してください – Theopap

+0

これはメソッドのスコープ内に' token'変数が定義されていないためです。私はちょうどそれを修正して私の答えを更新しました。 –

+0

実際に私は念願の確認トークンの後に、これを実装する方法についてのアイデアはありますか? – Theopap

0
@store.send_confirmation_instructions.deliver 

は、これが確認トークンを生成し、同様にメールを送信します。

関連する問題