Rails 3 with Agile Web Development Book、TaskHでメールを送信する方法を学んでいます。ただし、次のエラーが発生し続けます。
ArgumentError in OrdersController#create
wrong number of arguments (1 for 0)
Rails.root: /Applications/XAMPP/xamppfiles/htdocs/rails_projects/TUTORIALS/depot
Application Trace | Framework Trace | Full Trace
app/mailers/notifier.rb:4:in `order_received'
app/controllers/orders_controller.rb:57:in `block in create'
app/controllers/orders_controller.rb:52:in `create'
私はあちこちでsetup_mail.rbを使用して、 Gmailの構成に関する同様の議論を見てきましたが、エラーを取り除くことができませんでした。
私のconfig/environment.rbファイル(dev / test / productにも同じものが必要なため)には、xxxxとyyyyyのGmailの詳細があります。
Depot::Application.configure do
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => "plain",
:user_name => "xxxxxx@gmail.com",
:password => "yyyyyyy",
:enable_starttls_auto => true
}
end
model / notifier/order_received.text.erbには次のものがあります。
Dear <%= @order.name %>
Thank you for your recent order from The Pragmatic Store.
You ordered the following items:
<%= render @order.line_items %>
We'll send you a separate e-mail when your order ships.
そして最後に、models / controller/orders_controllerにはNotifierという行を持つdefcreateメソッドがあります。
def create
@order = Order.new(params[:order])
@order.add_line_items_from_cart(current_cart)
respond_to do |format|
if @order.save Cart.destroy(session[:cart_id])
session[:cart_id] = nil
Notifier.order_received(@order).deliver
format.html { redirect_to(store_url, :notice => 'Thank you for your order.') }
else
format.html { render :action => "new" }
format.xml { render :xml => @order.errors, :status => :unprocessable_entity }
end
end
end
メールの設定が正しく行われていないようですが、どちらかはわかりません。ありがとう!
編集:私はそれを解決することができました!smtpの代わりにsendmailを使用しました。引数の数エラーに関しては、app / mailers/notifer.rbは次のようになります。
class Notifier < ActionMailer::Base
default :from => 'Sam Ruby <depot@example.com>'
def order_received(order)
@order = order
mail :to => order.email, :subject => 'Pragmatic Store Order Confirmation'
end
def order_shipped(order)
@order = order
mail :to => order.email, :subject => 'Pragmatic Store Order Shipped'
end
end
私の電子メールとすべてはまだ機能しますが、SMTPが機能しない理由を誰かが知っているかどうか、そしてsendmailが機能するかどうか知りたいです。