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?
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
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.
Related
I have a Driver form (which is basically the user - I can do current_driver and stuff) and one of the fields is a boolean checkbox for 'subscribe to newsletter'.
I want to put this form on multiple pages that do not share the same controller, i.e Dashboard which has a pages controller.
I am using a partial to do this so i can just add the partial to a template easily.
I believe that the form should post to edit_driver_path as it's the driver form? At the moment when I submit the form, I get "No route matches [POST] "/drivers/dashboard/edit".
Am I on the right path here?
Let me know if I need to post controllers, forms or whatever.
Pretty stumped at the moment trying to figure something out. I have a modal that shows a table, and for each of the entries in the table, I have actions (i.e., show, edit, delete, etc). When the user clicks on "Edit" for an entry row in this model, I want it to populate another model with a form to show the data associated with that entry.
Is there a convenient way to do this? For one, I do not know how to pass a parameter to a modal from another modal. I don't know how to make this form "reinitialize" after it's already been rendered when the first page is loaded.
Any suggestions?
I have been in the same situation and I suggest that you just keep the one modal and replace the contents through AJAX (IMO). Once you have rendered into the modal in the first place, your links can then just render as AJAX the same way that they would and overwrite the information inside the modal. The way I did it was this:
Populate the modal (you've already done that).
Create a link = link_to "Text", "url", remote: true (let's say this is the edit action).
Run the edit action in the controller as usual.
The edit.js.erb file would contain one line: $('#Modal_content').html("<%= j render 'edit' %>") (#Modal_content is just a div that I put in my modal so that I can replace all the contents without messing up the close button and other modal required html).
The _edit.html.erb file is called where you would put all of what you needed that comes from the edit action.
As for passing information, the id is passed through the link that you click on to call the controller#edit action.
Let me know if you need more details, but that should get you most of the way there.
Sorry, only have been using rails for 10 day and I'm completely lost. Have a post model/controller and comment model/controller.
In post/show, I want to click an ajax button and replace a div (#addcomment) with the partial generated from comment/new (The new action takes two params and builds a comment for an ajax form partial). The comment/new partial is an add comment form with remote => true.
Anyone willing to point me in the right direction?
Tried using an ajax button in the view, that calls an action that replaces the div with the comment/new but it didn't work.
I'm working on the MVC app where I've to generate the report in the form of HTML page. If the user click the print icon, I've to show the HTML page to user. If the user click on email icon, I've to send email with same HTML page attachment. I'm trying to find a way where I can use the same code to generate the HTML in both cases of email and print. Please provide your suggestions.
What you really want and did not know how to formulate is Render view to string. Then you can do whatever you want with the contents of that string.
Start here
Render a view as a string
but this subject continues in many other questions too (or you can Google it) and you will discover much more information.
Your Controller has to decide what to do.
User clicked print. Controller action: collect data, prepare the View, display as HTML page
User clicked email. Controller action: collect data, prepare the View, call on an email-function and use the output of the HTML page as an attachment.
i just started building a small test app to help me learn MVC. i have a view that displays user comments. Under each comment i would like to have a reply action link. Clicking on the link should return a small form for adding a comment directly above the reply link.
What is the general approach for this? I'm imaging the form would be a partial view that i can somehow return using the reply link. Thanks for any help!
Using jQuery to retrieve and post the forms in partial views is how I would do it.
Just return partial view to be loaded by jQuery load:
$('#comment').load('/MyController/ActionReturnsPartial');
You should not have to retrieve anything from the server if the user is not providing any extra information along with the retrieval.
Instead of retrieving the form when the user clicks, just let the page render a form below each comment. Put the form in a div with style="display: none;". Then, when the user cliks the link, use jQuery to show the form. Something like
$('.commentlink').click(function(){
$(this).closest('div').find('.formdiv').show();
});
You may also be able to use jQuery's .toggle() method.