私はレールに非常に慣れていないので、gem griddler を使用して受信メールを解析していました。私は github サイトのすべてのコードを使用しました。emailprocessor.rb の例は次のとおりです。
class EmailProcessor
def initialize(email)
@email = email
end
def process
//re-done with help from @Kris
user = User.find_or_create_by(email: @email.from[:email]) do |u|
u.email = @email.from[:email]
u.name = @email.from[:name]
end
user.posts.create!(
subject: @email.subject,
body: @email.body,
attachment: @email.attachments,
from: @email.from[:email]
)
end
end
どういうわけかどこかで投稿を宣言する必要があることは知っていますが、こことレールサイトを見回しましたが、作成に役立つものは何も見つかりませんでした。メール サーバーがページに投稿しようとしたときに heroku logs -t を実行すると、タイトルにエラーが表示されます。
必要な可能性のある残りのファイルと、私が試したことは次のとおりです。
ユーザー.rb:
class User < ActiveRecord::Base
has_many :posts
end
Post.rb:
class Post < ActiveRecord::Base
belongs_to :user
end
create_posts.rb
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :subject
t.string :body
t.string :from
t.string :attachment
t.timestamps
end
end
end
users_controller.rb
class UserController < ApplicationController
def list
@users = User.find(:all)
end
def index
@users = User.all
end
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
def edit
end
def create
@user = User.new(params[:user])
if @user.save
redirect_to :action => 'list'
else
render :action => 'new'
end
end
end
post_controller.rb
class PostController < ApplicationController
def list
@posts = Post.find(:all)
end
def index
@posts = Post.all
end
def show
@post = Post.find(params[:id])
end
def new
@post = Post.new
end
def edit
end
def create
@post = Post.new(params[:post])
if @post.save
redirect_to :action => 'list'
else
@post = Subject.find(:all)
render :action => 'new'
end
end
end
どんな助けも本当に感謝しています。私が間違っていることを知りたいので、将来それを避けることができます