내 레일 애플리케이션에서 수신 이메일을 수신하고 특정 방식으로 구문 분석 할 수있는 기능이 필요합니다.Rails 이메일 구문 분석
incoming_controller.rb
class IncomingController < ApplicationController
skip_before_action :verify_authenticity_token, only: [:create]
skip_before_action :authenticate_user!, only: [:create]
def create
# Find the user
user = User.find_by(email: params[:sender])
# Find the topic
topic = Topic.find_by(title: params[:subject])
# Assign the url to a variable after retreiving it from
url = params["body-plain"]
# If the user is nil, create and save a new user
if user.nil?
user = User.new(email: params[:sender], password: "password")
user.save!
end
# If the topic is nil, create and save a new topic
if topic.nil?
topic = Topic.new(title: params[:subject], user: user)
topic.save!
end
bookmark = topic.bookmarks.build(user: user, url: url, description: "bookmark for #{url}")
bookmark.save!
# Assuming all went well.
head 200
end
end
나는 단지 3 개 값 = 사용자 추출 할 수있는이 컨트롤러를 사용하여 : 보낸 사람, 주제 : 제목과 URL을 "몸 일반".
전자 메일에 4 번째 값을 추가하여 a : 설명을 구문 분석 할 수 있습니까?
설명으로 인식 될 수 있도록 전자 메일의 텍스트를 어떻게 설정합니까? 예를 들어 전자 메일의 제목을 주제와 같게 설정합니다. 설명과 동일하게 이메일에서 무엇을 설정할 수 있습니까? – davefogo
그건 컨트롤러를 호출하는 것에 달려 있습니다 ... 전자 메일을 해싱으로 구문 분석하고 컨트롤러 작업에 제출하는 설정을받는 전자 메일이 있다고 가정합니다. 이를 제어 할 수 있으면 해시에 param을 추가 할 수 있습니다. 그렇게 할 수 없다면 편집 된 답변에서 설명한 것처럼 이메일 본문에 추가 할 수 있습니다. – rmhunter
당신이 대답에서 설명한 방법을 시도하고 있지만 url과 description은 params에 의해 선택되지 않습니다. 둘 다 nil로 읽습니다. – davefogo