私は解決策を見つけるのに苦労しています(ほぼ3日)incoming_controller.rbの私のコードは正しいようです.Railsコンソールでテストしたところ、唯一の問題はメールを送信するときです(私のgmailから)アカウント) をメールガンのメールに送信すると、宣言したルートが Rails アプリに接続されず、メールガンのログに警告が表示されます。
私がやろうとしているのは、ユーザーがメールを送信して本文のコンテンツをブックマークに変換し、それをデータベースに保存し、メールの件名をトピックとして保存できるようにすることです。
ここに私のroutes.rbファイルがあります:
Rails.application.routes.draw do
devise_for :users
get 'welcome/index'
get 'welcome/about'
root to: 'welcome#index'
post :incoming, to: 'incoming#create'
end
私のcoming_controller.rbファイル:
class IncomingController < ApplicationController
skip_before_action :verify_authenticity_token, only: [:create]
def create
@user = User.find_by(email: params[:sender])
@topic = Topic.find_by(title: params[:subject])
@url = params["body-plain"]
if @user.nil?
@user = User.new(email: params[:sender], password: "temp0rary_passw0rd")
@user.skip_confirmation!
@user.save!
end
if @topic.nil?
@topic = @user.topics.create(title: params[:subject])
end
@bookmark = @topic.bookmarks.create(url: @url)
head 200
end
end
トピックはユーザーに属し、多くのブックマークを持っています, ユーザーは多くのトピックを持っています, ブックマークはトピックに属しています.
また、私のmail.rbファイルは次のとおりです。
ActionMailer::Base.smtp_settings = {
port: 587,
address: 'smtp.mailgun.org',
user_name: ENV['MAILGUN_SMTP_LOGIN'],
password: ENV['MAILGUN_SMTP_PASSWORD'],
domain: 'appfc266c436eb04ebaae05a3f3f8ad7e49.mailgun.org',
authentication: :plain,
content_type: 'text/html'
}
ActionMailer::Base.delivery_method = :smtp
# Makes debugging *way* easier.
ActionMailer::Base.raise_delivery_errors = true
注: mailgun は、Devise からユーザーに電子メールの確認指示を送信することでうまく機能するため、正しく構成されています。私ができないのは、mailgun で電子メールを受信し、incoming_controller のパラメーターを介して Rails db に保存することです。
私は何を間違っていますか?
私のメールガンルートは次のとおりです。
フィルター式: catch_all()
アクション: forward(" http://bookmark-this.herokuapp.com/incoming/ ")
メールを送信したときに mailgun に表示される警告ログは次のとおりです。
github のプロジェクト リポジトリは次のとおりです: https://github.com/bntzio/bookmark-this
どうもありがとう!