2012-02-08 3 views
1

문제

나는 선물에 대한 서약을 할 수있는 앱이 있습니다. 서약서가 작성되면 이메일 확인서를 원저자에게 보내야합니다. 메일을 보내려고 서버가 500 Internal Server Error을 발행 중입니다.ActionMailer가 내 mongoid 객체를 전달하지 않는 이유는 무엇입니까?

상황 :

  • 루비 내가 Actionmailer 사용했습니다 1.3.1

2.4.3

  • 얇은 레일 3.2.0
  • Actionmailer 3.2.0
  • Mongoid에 이전 응용 프로그램에서,하지만 이것은 처음 Mongoid와 함께 일하는 것입니다.

    코드

    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에 대한 호출을 추가, 우리는 얻는다.

    어떤 조언이 있으십니까? :)

  • +0

    'cat -v pledge_mailer.rb'을 시도해보십시오. 이상한 바이트가있는 곳을 보여 주어야합니다. –

    +0

    @muistooshort 감사합니다. 나는 다른 바이트들을 발견하지 못했다. 그러나 나는 Mischa의 대답에 따라 그것을 다시 만들었고 문제가 수정되었습니다. –

    답변

    2

    코드가 정상적으로 보입니다. "멀티 바이트 문자 (US-ASCII)가 유효하지 않습니다"라는 오류가 발생했습니다. pledge_mailer.rb을 처음부터 다시 만들고 US-ASCII 대신 charset UTF-8로 저장하는 것이 좋습니다.

    +0

    감사합니다. @mischa. 이것은 트릭을했다 :) –

    관련 문제