Hola a todos, este es mi post primer post, gracias por leerme. Estoy
intentando realizar un ejemplo muy basico para enviar mails a traves
gmail usando smtp, por lo que he leido en versiones anteriores de rails
era necesario instalar un plugin, no asi en la version actual. yo uso
rails v3.2.3
el error que me da es:
ArgumentError in EmailerController#index
wrong number of arguments (1 for 0)
parece ser que no he inicializado algo, pero no se que es. He hecho lo
siguiente:
rails mail-example
#
# generamos solamente el modelo Emailer, esto creara
# /app/model/emailer.rb y una carpeta para en app/views
#
ruby script/generate mailer Emailer
#
# crea un fichero /config/initializers/mail.rb con el contenido
# de la configuracion, como sigue
#
# Email settings
ActionMailer::Base.delivery_method = :smtp #modo de entrega
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true, #solo para gmail
:address => "smtp.gmail.com",
:port =>587,
:domain => "yourapplication.com",
:authentication => :plain,
:user_name => "mi_cuenta_de_gmail@gmail.com",
:password => "el_password_de_mi_cuenta"
}
#
# rellenamos el modelo emailer.rb con
#
class Emailer < ActionMailer::Base
def contact(recipient, subject, message, sent_at = Time.now)
@subject = subject
@recipients = recipient
@from = 'no-reply@yourdomain.com'
@sent_on = sent_at
@body["title"] = 'Este es el titulo del mail \n'
@body["email"] = 'sender@yourdomain.com \n'
@body["message"] = message
@headers = {}
end
end
#
# creo el controller
#
ruby script/generate controller Emailer
#
# rellenamos el controller con los metodos write send, y sended
#
def write
end
def send
end
def sended
end
#
# crea las siguiente views
# /app/views/emailer/write.html.erb
# /app/views/emailer/sended.html.erb
#
# rellenamos la vista write.html.erb
#
<h2> Redactar mensaje </h2>
<% form_tag 'fsendmail' %>
<hr>
destinatario
<%= text_field_tag 'destino'%>
<hr>
asunto
<%= text_field_tag 'asunto'%>
<hr>
mensaje
<%= text_area_tag 'mensaje'%>
<hr>
<% submit_tag 'send'%>
#
# rellenamos el metodo send del controlador
#
def send
#usando los parametros enviados del usuario
result =
deliver_contact(params["destino"],params["asunto"],params["mensaje"])
params["result"] = result
redirect_to :action=>'sended'
end
#
# rellenamos la vista sended.html.erb
#
<h1> datos correo</h1>
</br>
result <%=params["result"]%></br>
<hr>
email <%=params["destino"]%> </br>
email2 <%=@email%></br>
subject <%=params["asunto"]%></br>
recipient <%=params["destino"]%> </br>
message <%=params["mensaje"]%> </br>
# arranco el servidor ruby script/server
# pongo la url 'http://127.0.0.1:3000/emailer'
ArgumentError in EmailerController#index
wrong number of arguments (1 for 0)
Gracias por adelantado
on 2009-06-22 19:40
on 2009-06-22 20:08
Prueba este plugin[1]. Y me cuentas [1] http://douglasfshearer.com/blog/gmail-smtp-with-ruby-on-rails-and-actionmailer 2009/6/22 Asaf Asaf <ruby-forum-incoming@andreas-s.net>
on 2009-06-22 21:16
Muchas Gracias Andres por responder, he hecho un nuevo proyecto, he
instalado el plugin, pero me sigue dando el mismo error.
¿no me hara falta algun require ?, en la pagina del autor no he visto
nada.
ArgumentError in EmailerController#write
wrong number of arguments (1 for 0)
te detallo lo que he hecho esta vez,
rails mail-example
ruby script/generate mailer Emailer
ruby /script/plugin install
http://svn.douglasfshearer.com/rails/plugins/action_mailer_optional_tls
#/config/initializers/mail.rb
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:tls => true, #solo para gmail
:address => "smtp.gmail.com",
:port =>587,
:domain => "yourapplication.com",
:authentication => :plain,
:user_name => "mi-direccion-de-gmail@gmail.com",
:password => " "
}
ruby script/generate mailer Emailer
ruby script/generate controller Emailer write send sended
# rellenamos el modelo emailer.rb con
class Emailer < ActionMailer::Base
def contact(recipient, subject, message, sent_at = Time.now)
@subject = subject
@recipients = recipient
@from = 'no-reply@yourdomain.com'
@sent_on = sent_at
@body["title"] = 'Este es el titulo del mail \n'
@body["email"] = 'sender@yourdomain.com \n'
@body["message"] = message
@headers = {}
end
end
# rellenamos la vista write.html.erb
<h2> Redactar mensaje </h2>
<% form_tag 'fsendmail' %>
<hr>
destinatario
<%= text_field_tag 'destino'%>
<hr>
asunto
<%= text_field_tag 'asunto'%>
<hr>
mensaje
<%= text_area_tag 'mensaje'%>
<hr>
<% submit_tag 'send'%>
# rellenamos el metodo send del controlador
#
def send
#usando los parametros enviados del usuario
result =
deliver_contact(params["destino"],params["asunto"],params["message"])
params["result"] = result
redirect_to :action=>'sended'
end
# cargo el servidor
# accedo a la url: 'http://127.0.0.1:3000/emailer/write'
sale el error:
' ArgumentError in EmailerController#index wrong number of arguments
(1 for 0)'
al final del log sale lo siguiente, por si te ayuda:
/home/asaf/.gem/ruby/1.8/gems/rails-2.3.2/lib/commands/server.rb:111
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
script/server:3
on 2009-06-22 21:39
>>ArgumentError in EmailerController#index wrong number of arguments
Puedes mostrar el metodo index de EmailerController ??
2009/6/22 Asaf Asaf <ruby-forum-incoming@andreas-s.net>
on 2009-06-22 21:54
Andrés Gutiérrez wrote: >>>ArgumentError in EmailerController#index wrong number of arguments > > Puedes mostrar el metodo index de EmailerController ?? > > > 2009/6/22 Asaf Asaf <ruby-forum-incoming@andreas-s.net> Gracias de nuevo!!! este es mi unico controller al completo: class EmailerController < ApplicationController def index end def write end def send #usando los parametros enviados del usuario result = deliver_contact(params["destino"],params["asunto"],params["message"]) params["result"] = result redirect_to :action=>'sended' end def sended end end
on 2009-06-22 22:11
parece que dice que le quieres pasar a tu metodo index no admite ninguno. Repasa en tu código donde llamas al meto index y mira a ver cuantos parametros/argumentos le pasas Un saludo 2009/6/22 Asaf Asaf <ruby-forum-incoming@andreas-s.net>
on 2009-06-23 17:21
Hola, gracias Andres. Para dejar constancia al final lo arregle pero
rehaciendolo por completo, y no se a que era debido el error.
pongo el entorno sobre el que lo he probado por si a alguien le es de
utilidad:
ruby 1.8.7
rails 2.3.2
actionmailer (2.3.2, 2.2.2)
actionpack (2.3.2, 2.2.2)
activerecord (2.3.2, 2.2.2)
activeresource (2.3.2, 2.2.2)
activesupport (2.3.2, 2.2.2)
gettext (2.0.4)
locale (2.0.4)
rails (2.3.2, 2.2.2)
rake (0.8.7)
rubygems-update (1.3.4, 1.3.3)
dejo aqui como lo hice
==============================================================
send email with gmail smtp server
==============================================================
rails send-mail-with-gmail
cd send-mail-with-gmail
#
# generamos solamente el modelo Emailer, esto creara
# /app/model/emailer.rb y una carpeta para en app/views
#
ruby script/generate mailer Emailer
#
# crea un fichero /config/initializers/mail.rb con el contenido
# de la configuracion, como sigue
#
# Email settings
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true, #solo para gmail
:address => "smtp.gmail.com",
:port =>587,
:domain => "gmail.com",
:authentication => :plain,
:user_name => "your-gmail-account@gmail.com",
:password => "your-gmail-password"
}
#
# en la primera linea configuramos el action mailer
# para usar smtp como metodo de entrega
#
# Otra opcion seria configurar ActionMailer para usar
# sendmail si es sobre Unix/Gnu-linux
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.delivery_method = :sendmail
#
# rellenamos el modelo emailer.rb con
#
class Emailer < ActionMailer::Base
def email_template(recipient, subject, message, sent_at = Time.now)
@subject = subject
@recipients = recipient
@from = 'no-reply@yourdomain.com'
@sent_on = sent_at
@body["title"] = 'Este es el titulo del mail \n'
@body["email"] = 'sender@yourdomain.com \n'
@body["message"] = message
@headers = {}
end
end
#
# creamos la vista del del correo en
/app/views/emailer/email_template.html.erb
# notese que si quisieramos una vista en texto plano el fichero se
# llamaria email_template.text.erb
<h1> hi this is a template for a new email <h1>
#
# crea el controller para
#
ruby script/generate controller Emailer
#
# rellenamos el controller con los metodos
# write send, y sended
def write_email
end
def send_email
logger.debug "send_email begin "
result =
Emailer.deliver_email_template(params["destino"],params["asunto"],params["mensaje"])
return if request.xhr?
render :text => 'Message sent sucessfully'
logger.debug "send_email end "
end
#
# crea las siguiente views
# app/views/emailer/write.html.erb
# app/views/emailer/send_mail.html.erb
<h2> Redactar mensaje </h2>
<% form_tag( :action=>'send_email') do %>
<hr>
destinatario
<%= text_field_tag 'recipient'%>
<hr>
asunto
<%= text_field_tag 'subject'%>
<hr>
mensaje
<%= text_area_tag 'message'%>
<hr>
<%= submit_tag 'Send Email'%>
<%end%>
# arranca el servidor
ruby script/server
# accede a la url
http://127.0.0.1:3000/emailer/write
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.