Reputation: 355
In my rails app I'm trying to add a contact user popup box which delivers an email message to a user.
I have the javascript in place to display the popup form, which is itself a partial.
When the user clicks submit on the contact form it calls a controller action which delivers the mail. After submitting the message I want to stay on the same page, but hide the popup box. My problem is that I can't get the controller action which delivers the mail not to render its own view. I tried
render nothing: true
But that simply renders a blank page.
My form is set up as follows
= form_tag({:controller => 'users', :action => 'contact_user'}, :method => 'put') do
And in my routes config I have
resources :users
collection do
put 'contact_user'
end
Upvotes: 3
Views: 2135
Reputation: 4293
If you submit your form via AJAX, you can do what you're trying to do.
Adding :remote => true
to your form will accomplish this:
= form_tag({:controller => 'users', :action => 'contact_user'}, :method => 'put', :remote => true) do
Now, the form submission will hit your controller as an AJAX request. You should then be able to either render nothing, as you suggested, or even do something like render a .js.erb
to execute some Javascript instead (say, to hide the popup you're talking about).
Upvotes: 8