2016-12-14 13 views
-1

ボタンをクリックして1人のユーザーが別のユーザーにメールを送信できるようにしたい。彼らは「あなたは[あなた]によって挑戦されました!」という自動生成された電子メールを受け取ります。したがって、ビューには、ユーザーのリストから選択するためのドロップダウンメニューと、そのユーザーにこの電子メールを送信する「チャレンジ」ボタンがあります。私はすでに登録メールを送信するメーラーを設定しました。ここでRuby on Rails - 1人のユーザーが別のユーザーにメールを送信する - メーラー

はメールです:

<!DOCTYPE html> 
<html> 
<head> 
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> 
</head> 
<body> 
<h1>You have been challeneged by, <%= @opponent.student_name %>.</h1> 

</body> 
</html> 

は、ここに私のusermailer.rb(私のユーザーが「学生」と呼ばれます)

def welcome(student) 
    @student = student 

    mail(:to => student.email, :subject => "Welcome to the DIT Judo club!") 
    end 

    def challenge(student, opponent) 
    @student = student 
    @opponent = opponent 
    mail(:to => student.email, :subject => "You have been challeneged to a Judo match!") 
    end 
end 

は、ここであなたがそれを見たい場合はコンフィグメーラーのものだだ:

config.action_mailer.raise_delivery_errors = true 

    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.smtp_settings ={ 
     :enable_starttls_auto => true, 
     :address => 'smtp.gmail.com', 
     :port => 587, 
     :domain => 'smtp.gmail.com', 
     :authentication => :plain, 
     :user_name => 'xxxxx', 
     :password => 'xxxxxx' 
    } 

基本的にビューでは、現在のユーザー(学生)が別のユーザーを選択するとドロップダウンしたいユーザー(生徒)に送信し、送信をクリックしてチャレンジメールをトリガーすることができます。私は誰かがそれをやるのを助けることができるレールが新です。ルートフォルダで

:私のインデックスで

get 'challenge', :to=>'usermailer#challenge' 

    resources :matches do 
     put :challenge 
    end 

<div> 
Challenge another student to a match! 
    <div class="field"> 
    <%= f.label :opponent %><br> 

    <%= f.collection_select :opponent, Student.all, :id, :student_name %> 
    </div> 
    <%= link_to 'challenge', match challenge_path([current studentID ??], [opponent from collection]), method: :put %> 

</div> 

答えて

0

あなたwelcomechallenge方法は、ちょうどメールオブジェクトを作成し、戻ってきている。ここ

は私のかすかな試みです。実際に送信するには、メールオブジェクトでdeliverに電話する必要があります。詳細については、the documentationの「メーラ呼び出し」を参照してください。

+0

はいごめんなさい申し訳ありませんが、回答に追加することを忘れてしまいました。登録のために.deliverを行う行があります。私は自分のチャレンジクラスのためにそれをどうやって行うのか分かりません!私はそれを構築する方法を知らないので、あなたは挑戦するユーザーを選んで、それを実現させることができるようにします。 – NiallRedmond

+0

チャレンジフォームの提出を処理しているコントローラーであれば、そうすることができます。 – Brian

+0

でも、どうすればいいですか? – NiallRedmond

関連する問題