2012-10-15 47 views
0

在我的Rails 3.2的項目,我有一個表格中app/views/posts/電子郵件通知

<%= form_for(@post) do |post_form| %> 
    ... 
    <div class="field"> 
    <%= post_form.label :email %><br /> 
    <%= post_form.text_field :email %> 
    </div> 
    <div class="field"> 
    <%= post_form.label :title %><br /> 
    <%= post_form.text_field :title %> 
    </div> 
    <div class="field"> 
    <%= post_form.label :content %><br /> 
    <%= post_form.text_field :content %> 
    </div> 
    <div class="actions"> 
    <%= post_form.submit %> 
    </div> 
<% end %> 

然後create功能posts_controller.rb

def create 
    @post = Post.new(params[:post]) 
    if @post.save 
    format.html { redirect_to @post } 
    else 
    format.html { render action: "new" } 
    end 
end 

創造new.html.erb一個新的職位當用戶提交一個帖子,我想發送電子郵件通知到email,即「您已經提交了標題爲title和內容content的帖子。」我怎樣才能做到這一點?

回答

0

你必須做一個郵件設置初始化以及應用程式/郵件程序/文件夾

然後,user_post_mailer.rb可以調用

UserMailer.post_confirmation(@用戶).deliver

從你控制器

Railscast mailer episode