문제
나는 선물에 대한 서약을 할 수있는 앱이 있습니다. 서약서가 작성되면 이메일 확인서를 원저자에게 보내야합니다. 메일을 보내려고 서버가 500 Internal Server Error
을 발행 중입니다.ActionMailer가 내 mongoid 객체를 전달하지 않는 이유는 무엇입니까?
상황 :
- 루비 내가 Actionmailer 사용했습니다 1.3.1
2.4.3
코드
class Pledge
include Mongoid::Document
field :name, :type => String
field :email, :type => String
field :amount, :type => Float
embedded_in :gift
end
class PledgesController < ApplicationController
def create
@gift = Gift.find(params[:gift_id])
@pledge = @gift.pledges.new(params[:pledge])
respond_to do |format|
if @pledge.save
PledgeMailer.pledge_confirmation(@pledge).deliver
format.html { redirect_to :root, notice: 'Pledge successfully created.' }
else
...
end
end
end
...
end
class PledgeMailer < ActionMailer::Base
default :from => "[email protected]"
def pledge_confirmation(pledge)
@pledge = pledge
mail(:to => pledge.email, :subject => "Thanks - pledge confirmation")
end
end
로그
그래서 선물 4f2695009f5b7f3464000001
에 대한 $42.42
을 약속 Sam Andreas
[email protected]
에서 가정 해 봅시다.
행복하게 Mongodb에 저장하고 :root
으로 리디렉션합니다.
Started POST "/gifts/4f2695009f5b7f3464000001/pledges" for 127.0.0.1 at 2012-02-08 14:13:21 +1100
Processing by PledgesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"EwgOwALSb8uUsT4Ow1+RBvAEihXKXoqKS1JA9ZfpUfg=",
"pledge"=>{"name"=>"Sam Andreas", "email"=>"[email protected]", "amount"=>"42.42"},
"commit"=>"Create Pledge", "gift_id"=>"4f2695009f5b7f3464000001"}
MONGODB danspressie_development['gifts'].find({:_id=>BSON::ObjectId('4f2695009f5b7f3464000001')}).limit(-1).sort([[:_id, :asc]])
MONGODB danspressie_development['gifts'].update({"_id"=>BSON::ObjectId('4f2695009f5b7f3464000001')}, {"$push"=>{"pledges"=>{"_id"=>BSON::ObjectId('4f31e8519f5b7f41d1000002'), "name"=>"Sam Andreas", "email"=>"[email protected]", "amount"=>42.42}}})
Completed 500 Internal Server Error in 11ms
SyntaxError (/Users/daniel/Dropbox/dev/src/danspressie/app/mailers/pledge_mailer.rb:4: invalid multibyte char (US-ASCII)
/Users/daniel/Dropbox/dev/src/danspressie/app/mailers/pledge_mailer.rb:4: syntax error, unexpected $end, expecting keyword_end
def pledge_confirmation(pledge)
^):
app/controllers/pledges_controller.rb:8:in `block in create'
app/controllers/pledges_controller.rb:6:in `create'
열심히 고투하지만 오류가 pledge_confirmation
에 위치를 확인할 수 없습니다 : PledgeMailer
에 대한 호출을 추가, 우리는 얻는다.
어떤 조언이 있으십니까? :)
'cat -v pledge_mailer.rb'을 시도해보십시오. 이상한 바이트가있는 곳을 보여 주어야합니다. –
@muistooshort 감사합니다. 나는 다른 바이트들을 발견하지 못했다. 그러나 나는 Mischa의 대답에 따라 그것을 다시 만들었고 문제가 수정되었습니다. –