Hi everyone,
Like so many other here, I too am new to Rails (and Ruby), and so far
it''s been a great experience. I haven''t been able to get
around one
problem though. When trying to use the mailer, I recieve an error like
this:
ActionView::ActionViewError in Tell_friend#send_email
No rhtml, rxml, or delegate template found for send_to_friend
The scenario is this:
A form on a page is submitted to a controller "tell_friend", action
"send_email".
In tell_friend_controller.rb''s send_email(), mail is sent like this:
TellFriend.deliver_send_to_friend(params[:address])
The model, tell_friend.rb, contains this:
class TellFriend < ActionMailer::Base
def send_to_friend(address)
# Email header info MUST be added here
@recipients = address
@from = xx-q89RzV0OsXQ@public.gmane.org
@subject = "Hello World"
# Email body substitutions go here
@body["address"] = address
end
end
Now, send_to_friend.rhtml *is* present in views/tell_friend/. But the
error message would seem to indicate that it is not the case.
Any ideas?
Thanks,
Doug
--
Posted via http://www.ruby-forum.com/.
Can you post all the code in tell_friend_controller.send_email() as well as any other code in tell_friend.rb (the mailer)? Thanks. Steven On Dec 23, 2005, at 7:14 PM, Doug wrote:> Hi everyone, > Like so many other here, I too am new to Rails (and Ruby), and so far > it''s been a great experience. I haven''t been able to get around one > problem though. When trying to use the mailer, I recieve an error like > this: > > ActionView::ActionViewError in Tell_friend#send_email > > No rhtml, rxml, or delegate template found for send_to_friend > > The scenario is this: > A form on a page is submitted to a controller "tell_friend", action > "send_email". > In tell_friend_controller.rb''s send_email(), mail is sent like this: > TellFriend.deliver_send_to_friend(params[:address]) > > The model, tell_friend.rb, contains this: > > class TellFriend < ActionMailer::Base > > def send_to_friend(address) > # Email header info MUST be added here > @recipients = address > @from = xx-q89RzV0OsXQ@public.gmane.org > @subject = "Hello World" > > # Email body substitutions go here > @body["address"] = address > end > > end > > > Now, send_to_friend.rhtml *is* present in views/tell_friend/. But the > error message would seem to indicate that it is not the case. > > Any ideas? > > Thanks, > Doug > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Hi Steven,
Here''s the controller code:
class TellFriendController < ApplicationController
def send_email
flash[:email_notice] = "E-mail sent to
#{params[''address'']}."
TellFriend.deliver_send_to_friend(params[:address])
# Go back to the post they were viewing
redirect_to :controller => ''view'', :action
=>
''view_post'', :params => {''id'' =>
params[:id], :address =>
params[:address] }
end
end
And here''s the mailer code:
class TellFriend < ActionMailer::Base
def send_to_friend(address)
@recipients = address
@from = xx-q89RzV0OsXQ@public.gmane.org
@subject = "Hello World"
# Email body substitutions go here
@body["address"] = address
end
end
Also, if anyone has any unrelated advice on the above code I''d love to
hear it too.
Thanks again,
Doug
Steven Smith wrote:> Can you post all the code in tell_friend_controller.send_email() as
> well as any other code in tell_friend.rb (the mailer)?
>
> Thanks.
> Steven
--
Posted via http://www.ruby-forum.com/.
Quick question, what directory does tell_friend.rb (the mailer) reside in? Also, do you have any sort of stack trace from when the error occurs? Thanks. On Dec 24, 2005, at 10:35 AM, Doug wrote:> Hi Steven, > > Here''s the controller code: > > class TellFriendController < ApplicationController > def send_email > flash[:email_notice] = "E-mail sent to > #{params[''address'']}." > TellFriend.deliver_send_to_friend(params[:address]) > # Go back to the post they were viewing > redirect_to :controller => ''view'', :action => > ''view_post'', :params => {''id'' => params[:id], :address => > params[:address] } > end > end > > > And here''s the mailer code: > > class TellFriend < ActionMailer::Base > > def send_to_friend(address) > @recipients = address > @from = xx-q89RzV0OsXQ@public.gmane.org > @subject = "Hello World" > > # Email body substitutions go here > @body["address"] = address > end > > end > > > Also, if anyone has any unrelated advice on the above code I''d love to > hear it too. > > Thanks again, > Doug > > > > Steven Smith wrote: >> Can you post all the code in tell_friend_controller.send_email() as >> well as any other code in tell_friend.rb (the mailer)? >> >> Thanks. >> Steven > > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Also, what is in the directory app/views/tell_friend/? Thanks. On Dec 24, 2005, at 10:35 AM, Doug wrote:> Hi Steven, > > Here''s the controller code: > > class TellFriendController < ApplicationController > def send_email > flash[:email_notice] = "E-mail sent to > #{params[''address'']}." > TellFriend.deliver_send_to_friend(params[:address]) > # Go back to the post they were viewing > redirect_to :controller => ''view'', :action => > ''view_post'', :params => {''id'' => params[:id], :address => > params[:address] } > end > end > > > And here''s the mailer code: > > class TellFriend < ActionMailer::Base > > def send_to_friend(address) > @recipients = address > @from = xx-q89RzV0OsXQ@public.gmane.org > @subject = "Hello World" > > # Email body substitutions go here > @body["address"] = address > end > > end > > > Also, if anyone has any unrelated advice on the above code I''d love to > hear it too. > > Thanks again, > Doug > > > > Steven Smith wrote: >> Can you post all the code in tell_friend_controller.send_email() as >> well as any other code in tell_friend.rb (the mailer)? >> >> Thanks. >> Steven > > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Steven Smith wrote:> what directory does tell_friend.rb (the mailer) reside in?tell_friend.rb is in models/> Also, what is in the directory app/views/tell_friend/?deliver_send_to_friend.rhtml send_to_friend.rhtml send_email.rhtml I tried a few filename combos trying to figure out what it''s looking for. Finally, the stack trace: /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_view/base.rb:282:in `pick_template_extension'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_view/base.rb:196:in `render_file'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_view/base.rb:227:in `render'' /usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.3/lib/action_mailer/base.rb:357:in `render'' /usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.3/lib/action_mailer/base.rb:352:in `render_message'' /usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.3/lib/action_mailer/base.rb:300:in `create!'' /usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.3/lib/action_mailer/base.rb:263:in `initialize'' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:18:in `new'' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:18:in `new'' /usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.3/lib/action_mailer/base.rb:223:in `method_missing'' #{RAILS_ROOT}/app/controllers/tell_friend_controller.rb:5:in `send_email'' What do you think? Thanks, Doug -- Posted via http://www.ruby-forum.com/.
I think you''ve pretty much done things the right way. I''ve heard of a couple of problems when there are extraneous views in the directory where the mail template is (app/views/tell_friend). As far as the mailer goes, I believe the only one you need is send_to_friend.rhtml so I''d remove the others from that directory if possible. Also, while it should make no difference, can you change your code in tell_friend_controller.send_email to something like the following just to see if a different error is produced: email = TellFriend.create_send_to_friend(params[:address]) TellFriend.deliver(email) instead of TellFriend.deliver_send_to_friend(params[:address]) Also, you may want to consider using a different name for your mailer (such as TellFriendMailer) as there _may_ be some sort of conflict with other views used in conjunction with the TellFriendController (which may be why there are other views in apps/views/tell_friend). If you do make this change, then you''d need to move send_to_friend.rhtml to the app/views/tell_friend_mailer directory. On Dec 24, 2005, at 2:03 PM, Doug wrote:> Steven Smith wrote: > >> what directory does tell_friend.rb (the mailer) reside in? > tell_friend.rb is in models/ > >> Also, what is in the directory app/views/tell_friend/? > deliver_send_to_friend.rhtml > send_to_friend.rhtml > send_email.rhtml > > I tried a few filename combos trying to figure out what it''s looking > for. > > Finally, the stack trace: > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_view/ > base.rb:282:in > `pick_template_extension'' > /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_view/ > base.rb:196:in > `render_file'' > /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_view/ > base.rb:227:in > `render'' > /usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.3/lib/action_mailer/ > base.rb:357:in > `render'' > /usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.3/lib/action_mailer/ > base.rb:352:in > `render_message'' > /usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.3/lib/action_mailer/ > base.rb:300:in > `create!'' > /usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.3/lib/action_mailer/ > base.rb:263:in > `initialize'' > /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:18:in `new'' > /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:18:in `new'' > /usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.3/lib/action_mailer/ > base.rb:223:in > `method_missing'' > #{RAILS_ROOT}/app/controllers/tell_friend_controller.rb:5:in > `send_email'' > > What do you think? > Thanks, Doug > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Steven Smith wrote:> I think you''ve pretty much done things the right way. I''ve heard of > a couple of problems when there are extraneous views in the directory > where the mail template is (app/views/tell_friend). As far as the > mailer goes, I believe the only one you need is send_to_friend.rhtml > so I''d remove the others from that directory if possible. Also, > while it should make no difference, can you change your code in > tell_friend_controller.send_email to something like the following > just to see if a different error is produced: > > email = TellFriend.create_send_to_friend(params[:address]) > TellFriend.deliver(email) > > instead of > > TellFriend.deliver_send_to_friend(params[:address]) > > Also, you may want to consider using a different name for your mailer > (such as TellFriendMailer) as there _may_ be some sort of conflict > with other views used in conjunction with the TellFriendController > (which may be why there are other views in apps/views/tell_friend). > If you do make this change, then you''d need to move > send_to_friend.rhtml to the app/views/tell_friend_mailer directory.Hi, I tried your suggestions twice, still no luck. Pretty bizarre. I think I''ll just outsource the emailing to a perl script for the time being, until I figure it out. Thanks for your help! Doug -- Posted via http://www.ruby-forum.com/.
Hi ,
I was facing similar problems but I was able to send an email using
sendmail finally. I created a directory called
my_mailer in {RAILS_ROOT}/apps/views/test/
MyMailer defined in my_mailer.rb inside the models directory
<<<<<<<<
class MyMailer < ActionMailer::Base
def sendmail (recipient)
recipients recipient
subject "test mail"
from "vivek-bi+AKbBUZKbby3iVrkZq2A@public.gmane.org"
body = { :text => "First mail" }
end
end
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.template_root = "app/views/test"
>>>>>>>>
<<<<<<Controller code
class TestController < ApplicationController
def index
@message = ''riding on rails''
end
def mail
MyMailer::deliver_sendmail ( params[:to] )
render :text => ''mail sent''
end
end
>>>>>
Does rails require the name to be my_mailer ? and should this have to be
inside models ? Cant we place it inside the controllers? I feel thats a more
natural place
Also the template has to be named sendmail.text.plain.rhtml in the
my_mailer directory
The question I have is what exactly needs to go into the view ? I had just
one line
<%= @body[:text] %>
But I get the error
ou have a nil object when you didn''t expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.[]
Any idea how I can access the body etc?
Thanks
Vivek
On 12/25/05, Doug
<doug.pfeffer+ror-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Steven Smith wrote:
> > I think you''ve pretty much done things the right way.
I''ve heard of
> > a couple of problems when there are extraneous views in the directory
> > where the mail template is (app/views/tell_friend). As far as the
> > mailer goes, I believe the only one you need is send_to_friend.rhtml
> > so I''d remove the others from that directory if possible.
Also,
> > while it should make no difference, can you change your code in
> > tell_friend_controller.send_email to something like the following
> > just to see if a different error is produced:
> >
> > email = TellFriend.create_send_to_friend(params[:address])
> > TellFriend.deliver(email)
> >
> > instead of
> >
> > TellFriend.deliver_send_to_friend(params[:address])
> >
> > Also, you may want to consider using a different name for your mailer
> > (such as TellFriendMailer) as there _may_ be some sort of conflict
> > with other views used in conjunction with the TellFriendController
> > (which may be why there are other views in apps/views/tell_friend).
> > If you do make this change, then you''d need to move
> > send_to_friend.rhtml to the app/views/tell_friend_mailer directory.
>
> Hi,
> I tried your suggestions twice, still no luck. Pretty bizarre. I think
> I''ll just outsource the emailing to a perl script for the time
being,
> until I figure it out.
>
> Thanks for your help!
> Doug
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
I tried to create a dir under apps/views/test/mymailer but it still can''t find the template. Anyone know any other way to fix it? THANKS -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bontina Chen wrote:> I tried to create a dir under apps/views/test/mymailer > > but it still can''t find the template. > Anyone know any other way to fix it? > > THANKSI found the possible solution. Just add require ''action_mailer'' in the yourmailer.rb It works for me. Hopw this helps. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---