开发者

Newbie Question: How to use `form_tag` helper in Rails 3 to create a simple Contact Us form?

How would I use form_tag (because I don't have a model) to create a contact us form with a name, email, and message field. Then on submit I would like to call a controller action t开发者_如何学编程hat would send an email to an email account. Sorry I'm new to Rails, but can someone point me in the right direction? Thanks!


you could check here , i have googled to it and read briefly , but seems to be all OK! http://www.railsmine.net/2010/03/rails-3-action-mailer-example.html

Have a nice day!

edit: ... in this example they use a model to store support message , it's a good idea , you have strong activerecord validation , a restfull action and an history of every message sent.

sorry for my english.


I've written a Rails Engine https://github.com/jdutil/contact_us that you can easily drop into any Rails 3+ application. I didn't add a Name field to the form, but you could fork the repo then modify it to suit your needs. Or you can simply review the code to snag any relevant pieces you are stuck on for making your own form. It does require the Formtastic gem since I wanted an easy way to hook into peoples existing form styles though.

To install the Engine add the contact_us gem to your Gemfile:

gem 'contact_us', '~> 0.0.8'

Run bundle and the install rake task:

$ bundle
$ bundle exec rake contact_us:install

Then just modify the generated initializer in /config/initializers/contact_us.rb to have the email you want the form submissions sent to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜