Ruby on rails 使用Rails-4发送电子邮件时出现的问题

Ruby on rails 使用Rails-4发送电子邮件时出现的问题,ruby-on-rails,email,ruby-on-rails-4,Ruby On Rails,Email,Ruby On Rails 4,任何人都可以帮我解决这个问题。我正在尝试向一个用户发送电子邮件。代码中没有显示错误,但无法向用户发送电子邮件。我的代码片段如下所述。请检查它并帮助我成功运行它 views/users/index.html.erb <h1>Send email to your friend</h1> <%= form_for @user,:url => {:action => 'create'} do |f| %> <%= f.text_field:n

任何人都可以帮我解决这个问题。我正在尝试向一个用户发送电子邮件。代码中没有显示错误,但无法向用户发送电子邮件。我的代码片段如下所述。请检查它并帮助我成功运行它

views/users/index.html.erb

<h1>Send email to your friend</h1>
<%= form_for @user,:url => {:action => 'create'} do |f| %>
    <%= f.text_field:name,placeholder:"Enter your name" %><br>
    <%= f.email_field:email,placeholder:"Enter your email" %><br>
    <%= f.submit "Send" %>
<% end %>
视图/user\u mailer/registration\u confirmation.text.erb

<%= @user.name%>
<h1>Thank you for registering</h1>
Click <%= link_to "here",users_new_path %>
development.rb

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = true

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations.
  config.active_record.migration_error = :page_load

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true

  # Asset digests allow you to set far-future HTTP expiration dates on all assets,
  # yet still be able to expire them through the digest params.
  config.assets.digest = true

  # Adds additional error checking when serving assets at runtime.
  # Checks for improperly declared sprockets dependencies.
  # Raises helpful error messages.
  config.assets.raise_runtime_errors = true

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true
end

我一直在关注这一点。我正在使用rails版本4.2.0和ruby 1.9.3。请帮助我成功运行它。谢谢..

提交formHello Dipak后,您正在重定向到索引页或成功。提交后,输入值将存储在db中,邮件应发送。如果成功保存并发送,邮件页将重定向到success.html.erb页面,否则它将停留在索引页面。那么这个问题的解决方案是什么呢?是的,我在代码中看到了。在这两种情况下,您都在重定向,这就是您无法正确获取错误的原因。请在您的创建操作的其他部分尝试
render:index
,看看您是否有任何错误,或者notOK Dipak让我这样做,我会很快确认您。再次感谢Dipak给了我这样的想法。现在它显示了创建操作的这一行(“UserMailer.registration\u confirmation(@user.deliver))中的一些错误错误为error:Errno::econnreference in UsersController#无法创建任何连接,因为目标计算机主动拒绝了它。-连接(2)请帮助我解决此错误。
class UsersController < ApplicationController
  def index
    @user=User.new
  end
  def create
    @user=User.new(users_params)
    if @user.save
      UserMailer.registration_confirmation(@user).deliver
      redirect_to :action => 'success'
    else
      redirect_to :action => 'index'
    end
  end
  def new

  end
  def success

  end
  private
  def users_params
    params.require(:user).permit(:name, :email)
  end
end
Rails.application.routes.draw do
 root 'users#index'
  post "users/create" => "users#create"
 get "users/success" => "users#success"
  get "users/new" => "users#new"
end
<%= @user.name%>
<h1>Thank you for registering</h1>
Click <%= link_to "here",users_new_path %>
class UserMailer < ApplicationMailer
  default :from => "w5call.w5rtc@gmail.com"
  def registration_confirmation(user)
    @user=user
    mail(:to => user.email, :subject => "Registered")
  end
end
ActionMailer::Base.smtp_settings = {
    :address              => "smtp.gmail.com",
    :port                 => 587,
    :domain               => "gmail.com",
    :user_name            => "w5call.w5rtc@gmail.com",
    :password             => "w5rtc123@",
    :authentication       => "plain",
    :enable_starttls_auto => true
}
ActionMailer::Base.default_url_options[:host] = "localhost:3000"
Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = true

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations.
  config.active_record.migration_error = :page_load

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true

  # Asset digests allow you to set far-future HTTP expiration dates on all assets,
  # yet still be able to expire them through the digest params.
  config.assets.digest = true

  # Adds additional error checking when serving assets at runtime.
  # Checks for improperly declared sprockets dependencies.
  # Raises helpful error messages.
  config.assets.raise_runtime_errors = true

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true
end