Simple Contact Form - ActiveRecord without a table

Hey,

This is hopefully a very basic question, though I couldn't find a nice tutorial for that. I want to make in Rails3 a simple contact form, but with validation. So I thought, that I would use ActiveRecord for that, but it's obvious that I don't want a table for that.

So the question is how to make such a form with validation in Rails3 DRY way?

I would be grateful for a piece of code for the controller and the class itself.

Thanks.

wardenik wrote in post #971297:

Hey,

This is hopefully a very basic question, though I couldn't find a nice tutorial for that. I want to make in Rails3 a simple contact form, but with validation. So I thought, that I would use ActiveRecord for that, but it's obvious that I don't want a table for that.

Is it obvious? Do you want to save any of the info entered into the form?

So the question is how to make such a form with validation in Rails3 DRY way?

I would be grateful for a piece of code for the controller and the class itself.

I believe you just need to use ActiveModel without the rest of ActiveRecord.

Thanks.

Best,

You can use the mail_form gem - it’s built on top of ActiveModel, so it acts like pretty similar to ActiveRecord models :slight_smile:

Hey,

This is hopefully a very basic question, though I couldn’t find a nice

tutorial for that.

I want to make in Rails3 a simple contact form, but with validation.

So I thought, that I would use ActiveRecord for that, but it’s obvious

that I don’t want a table for that.

So the question is how to make such a form with validation in Rails3

DRY way?

This is what you want: watch this: http://railscasts.com/episodes/219-active-model … this is the Rails 3 way of doing this ( if you are sure you don’t want to save the data). There was a more hacky way in Rails 2.