0

I want to have a contact form in a Bootstrap modal. Making a modal pop up was pretty simple.

The email will not go to the admin. The idea with my app is sort of like Airbnb, where users can have a house (one-to-one in my case). So on a show house page, a user can click a button to contact the owner. I can get the email from the relationship between the house and the user.

My contact form should not save to the database, just send an email. The only field I need is the message. I should be able to get the email from controller of the page serving the modal (that's why I don't want to introduce another controller).

There are some tutorials on making a contact form, such as this one: https://rubyonrailshelp.wordpress.com/2014/01/08/rails-4-simple-form-and-mail-form-to-make-contact-form/

But that creates a contact model, view, and controller. Right now my modal is a partial. How can I make that partial be the view for the contacts?

I feel like I shouldn't need a new model, view, and controller. Couldn't I just do this with a new mailer?

Terrytreks
  • 266
  • 3
  • 11
  • should the contact form have only an email and a description? do you want to store into the db or just send an email to the admin? – fedetaglia Aug 24 '15 at 10:00
  • I updated the question to note that I don't want to save anything in the database. Also, the email will go to another user, not the admin. – Terrytreks Aug 25 '15 at 05:26

2 Answers2

2

My question was probably dumb, due to my lack of understanding of Rails. I figured it out, and here is what I did, in order to help others.

The fact the form is in a modal does not matter. It's easy to render a form in a modal.

Because when you push the submit button, the form has to do something, a controller and route is needed. Then I needed a mailer. Basically this is the answer, but I did not need another view, since the form is already in my modal:

Contact Form Mailer in Rails 4

Community
  • 1
  • 1
Terrytreks
  • 266
  • 3
  • 11
0

For your action of controller create a js.erb file like contact.js.erb and render your form partial in that. For example

jQuery("#modal_pops").html("<%= j render 'your_modal'  %>");
jQuery("#model_container").modal("show");

and in that modal write your form. If you dont want to save that the information to database then just submit the form to an action and send email from that action. I hope you get it.

Jun Aid
  • 464
  • 7
  • 16