What is the most RoR friendly way of making a form mailer similar to this php one? http://tips-scripts.com/?tip=form_mail#tip Or is it easier just to use the php with RoR? -- Posted via http://www.ruby-forum.com/.
Sending emails from your Rails app is so easy, however I don''t think that is your point. Rails is not intended for replacing simple scripts like that on your website, but you certainly can. Rails is for building applications. Just look at the docs for ActionMailer. -- Timothy Johnson On Jun 26, 2006, at 8:13 AM, Rob Balfour wrote:> What is the most RoR friendly way of making a form mailer similar to > this php one? > > http://tips-scripts.com/?tip=form_mail#tip > > Or is it easier just to use the php with RoR? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks, I sure its simple if you know how but I can''t work it out and the ActionMailer doc doesn''t go into much detail. what I can''t work out is how connect the users form (with email & text area ) in the view to communicate to the actionmailer. -- Posted via http://www.ruby-forum.com/.
Rob Balfour wrote:> Thanks, I sure its simple if you know how but I can''t work it out and > the ActionMailer doc doesn''t go into much detail. > > what I can''t work out is how connect the users form (with email & text > area ) in the view to communicate to the actionmailer.I''ll give you sample code where I use a form to ask for someone''s e-mail address then I reset their user-pw: This is in a model... MailSender.rb class MailSender < ActionMailer::Base def sent(subject, body, from, recipient,sent_at = Time.now) @subject = subject @body = body @recipients = recipient @from = from @sent_on = sent_at end end Here is the form in a partial: <fieldset> <legend>Please Supply Email:</legend> <%= start_form_tag :action => :rpass%> <%= text_field_tag :email, params[:email] %> <%= submit_tag "Reset" %> <%= end_form_tag %> </fieldset> Here is the rpass action in the controller: def rpass @email = params[:email] @thisUser = User.find(:all, :conditions => "email=''#{@email}''") if @thisUser[0]!=nil @random = rand(1000000000).to_s @thisUser[0].change_password(@random) @thisUser[0].update() @thisUser[0].save @message = "Hello - Your password has been reset to: " + @random flash[:notice] = "Your password has been changed!" email = MailSender.create_sent("Password Reset", @message, @thisUser[0].email, asdf@asdf.com) MailSender.deliver(email) else flash[:notice] = "No User with that e-mail" end redirect_to :controller => "account", :action => "index" end Hope this helps -Ben -- Posted via http://www.ruby-forum.com/.
See an article I wrote on how to handle forms with validations. http://www.bphogan.com/learn/pdf/tableless_contact_form.pdf On 6/26/06, Ben Lisbakken <lisbakke@gmail.com> wrote:> > Rob Balfour wrote: > > Thanks, I sure its simple if you know how but I can''t work it out and > > the ActionMailer doc doesn''t go into much detail. > > > > what I can''t work out is how connect the users form (with email & text > > area ) in the view to communicate to the actionmailer. > > I''ll give you sample code where I use a form to ask for someone''s e-mail > address then I reset their user-pw: > > This is in a model... MailSender.rb > > > class MailSender < ActionMailer::Base > > def sent(subject, body, from, recipient,sent_at = Time.now) > @subject = subject > @body = body > @recipients = recipient > @from = from > @sent_on = sent_at > end > end > > > Here is the form in a partial: > <fieldset> > <legend>Please Supply Email:</legend> > <%= start_form_tag :action => :rpass%> > <%= text_field_tag :email, params[:email] %> > <%= submit_tag "Reset" %> > <%= end_form_tag %> > </fieldset> > > Here is the rpass action in the controller: > > > def rpass > @email = params[:email] > @thisUser = User.find(:all, :conditions => "email=''#{@email}''") > if @thisUser[0]!=nil > @random = rand(1000000000).to_s > @thisUser[0].change_password(@random) > @thisUser[0].update() > @thisUser[0].save > @message = "Hello - Your password has been reset to: " + @random > flash[:notice] = "Your password has been changed!" > email = MailSender.create_sent("Password Reset", @message, > @thisUser[0].email, asdf@asdf.com) > MailSender.deliver(email) > else > flash[:notice] = "No User with that e-mail" > end > redirect_to :controller => "account", :action => "index" > end > > > > > Hope this helps > -Ben > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060626/46bd4ef5/attachment.html
Brian Hogan wrote:> See an article I wrote on how to handle forms with validations. > > http://www.bphogan.com/learn/pdf/tableless_contact_form.pdfBrian Hogan you are a Legend! I have been looking for something like this for about 4 days now. You should add this to the Rails Wiki. Its on the wishlist http://wiki.rubyonrails.org/rails/pages/WishList Thanks again! David Smit -- Posted via http://www.ruby-forum.com/.
> Brian Hogan wrote: >> http://www.bphogan.com/learn/pdf/tableless_contact_form.pdfGreat - exactly what I needed. Huge thank you! -- Posted via http://www.ruby-forum.com/.
Even though it''s acknowledged in the article I posted, it wouldn''t have been possible without the inspiration from Rick Olson. Thanks Rick! On 6/27/06, Rob Balfour <rob_uk88@hotmail.com> wrote:> > > Brian Hogan wrote: > >> http://www.bphogan.com/learn/pdf/tableless_contact_form.pdf > > Great - exactly what I needed. Huge thank you! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060627/3d0128e6/attachment.html
Rob Balfour wrote:>> Brian Hogan wrote: >>> http://www.bphogan.com/learn/pdf/tableless_contact_form.pdfI ran into a problem that I can''t solve. When I click on Submit I get the following error: NoMethodError in <controller not set>#<action not set> undefined method `const_available?'' for FrontController:Class RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:234:in `traverse_to_controller'' generated/routing/recognition.rb:3:in `recognize_path'' -e:3:in `load'' -e:3 c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:234:in `traverse_to_controller'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:458:in `recognize!'' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in `dispatch'' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:117:in `handle_dispatch'' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:83:in `service'' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'' c:/ruby/lib/ruby/1.8/webrick/server.rb:155:in `start_thread'' c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start'' c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'' c:/ruby/lib/ruby/1.8/webrick/server.rb:94:in `start'' c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `each'' c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `start'' c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start'' c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start'' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:69:in `dispatch'' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__'' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in `require'' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__'' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in `require'' ./script/server:3 c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:234:in `traverse_to_controller'' generated/routing/recognition.rb:3:in `recognize_path'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:458:in `recognize!'' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in `dispatch'' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:117:in `handle_dispatch'' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:83:in `service'' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'' c:/ruby/lib/ruby/1.8/webrick/server.rb:155:in `start_thread'' c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start'' c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'' c:/ruby/lib/ruby/1.8/webrick/server.rb:94:in `start'' c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `each'' c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `start'' c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start'' c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start'' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:69:in `dispatch'' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__'' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in `require'' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__'' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in `require'' ./script/server:3 -e:3:in `load'' -e:3 Request Parameters: {"commit"=>"Send", "contact"=>{"name"=>"", "message"=>"", "subject"=>"", "email_address"=>""}} Any ideas on what its looking for. My code looks exactly like Brian''s -- Posted via http://www.ruby-forum.com/.
David Smit wrote:> Rob Balfour wrote: >>> Brian Hogan wrote: >>>> http://www.bphogan.com/learn/pdf/tableless_contact_form.pdf > > I ran into a problem that I can''t solve. > > When I click on Submit I get the following error: > > NoMethodError in <controller not set>#<action not set> > > undefined method `const_available?'' for FrontController:Class > > RAILS_ROOT: ./script/../config/.. > Application Trace | Framework Trace | Full Trace > > Request > > Parameters: {"commit"=>"Send", "contact"=>{"name"=>"", "message"=>"", > "subject"=>"", "email_address"=>""}} > > Any ideas on what its looking for. My code looks exactly like Brian''sContact View: <%=error_messages_for "contact" %> <%= start_form_tag :controller=>"front_controller", :action=>"send_contact_request" %> <table> <tr> <td>Name</td> </tr> <tr> <td><%= text_field("contact", "name") %></td> </tr> <tr> <td>Email</td> </tr> <tr> <td><%= text_field("contact", "email_address") %></td> </tr> <tr> <td>Subject</td> </tr> <tr> <td><%= text_field("contact", "subject") %></td> </tr> <tr> <td>Message</td> </tr> <tr> <td><%= text_area("contact", "message") %></td> </tr> </table> <%= submit_tag "Send" %> <%= end_form_tag %> Conrtoller: def contact @contact = Contact.new end def send_contact_request breakpoint @contact = Contact.new(params[''contact'']) if @contact.save begin Mailer::deliver_contact_message(@contact) flash[:notice] = "Success!" redirect_to :action=> "contact" rescue flash[:notice] = "It broke!" render :action=> "contact" end else render :action=> "contact" end end -- Posted via http://www.ruby-forum.com/.