2014-02-28 4 views
1

레일즈에서 루비의 보석에 mail_form과 보석 simple_form을 사용하고 있습니다 .4. 메일을 보내면 오류가 발생합니다. 실행 시간이 만료되었습니다. 내 양식에 문제가 있는지 알지 못합니다. .mail_form이 레일즈 4에서 루비를 사용하여 작동하지 않습니다


컨트롤러

#Form submitted 
def enquire 
    @message = ContactForm.new(enquiry_params) 
    flash.clear 

    if @message.valid? 
     @message.deliver 
     flash[:notice] = "Message Sent Thank You!" 
    else 
     flash[:error] = "Sorry, You Got Errors!" 
    end 

    respond_to do |format| 
     format.html { redirect_to contact_index_path } 
     format.js 
    end 
end 

private 

def enquire_params 
    params.require(:contact_form).permit(:name, :email, :message) 
end 

메일러

: 여기
def create 
    @contact = Contact.new(params[:contact]) 
    if @contact.valid? 
     @contact.deliver # error line is here 
    else 
     render :new 
    end 
    end 
+2

코드를 읽을 수 있도록 정리하려고했지만 실제로하려는 것을 잃어 버렸습니다.'end' /'else'는 의미가 없으며'end'가 없습니다. . – sevenseacat

+0

'end' 뒤에'else'를 넣을 뜻은 없습니다. – RSB

답변

0

우리가 사용하고있는 코드의 일부입니다 양식 ContactForm` '라는 메일러 사용하도록

우리는 그것을 설정 한 :

#app/mailers/contact_form.rb 
class ContactForm < MailForm::Base 
    attribute :name,  validate: true 
    attribute :email,  validate: /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i 
    attribute :message 

    #Simple SPAM Protection (needs to remain blank) 
    attributes :nickname, captcha: true 

    # Declare the e-mail headers. It accepts anything the mail method 
    # in ActionMailer accepts. 
    def headers 
    { 
     subject: "Website Enquiry", 
     to: AppConfig["company"]["enquiry"], 
     from: %("#{name}" <#{email}>) 
    } 
    end 
end 

보기

이는 사용

#app/views/enquiry_mailer/new_message.text 
Email: <%= @message.email %> 

Subject: <%= @message.subject %> 

Message: <%= @message.body %> 

당신에게 확실 너는이 모든 걸 가지고 있니?

관련 문제