Permalink
Browse files

Redirect URL on successful submissions is configurable. Fixes #33

  • Loading branch information...
1 parent fee8c23 commit fe1700c515d1ad4b8101ebc31db0064dee3889d3 Dan Madere committed with Jul 11, 2013
View
@@ -63,6 +63,11 @@ config.require_name = true
config.require_subject = true
```
+To redirect to a specific URL after a successful form submission:
+```ruby
+config.success_redirect = '/contact-success'
+```
+
### Views
To copy the view files to `app/views/contact_us`, and customize them to suit your needs run:
@@ -4,7 +4,7 @@ def create
@contact = ContactUs::Contact.new(params[:contact_us_contact])
if @contact.save
- redirect_to('/', :notice => t('contact_us.notices.success'))
+ redirect_to(ContactUs.success_redirect || '/', :notice => t('contact_us.notices.success'))
else
flash[:error] = t('contact_us.notices.error')
render_new_page
View
@@ -16,6 +16,9 @@ module ContactUs
# Formtastic or SimpleForm
mattr_accessor :form_gem
+ # URL after a successful submission
+ mattr_accessor :success_redirect
+
# Default way to setup ContactUs. Run rake contact_us:install to create
# a fresh initializer with all configuration values.
def self.setup
@@ -24,4 +24,7 @@
# config.form_gem = 'formtastic'
config.form_gem = nil
+ # Configure the redirect URL after a successful submission
+ config.success_redirect = '/'
+
end
@@ -9,12 +9,21 @@
end
it 'should redirect with success message if valid contact' do
+ ContactUs.success_redirect = nil
post :create, :contact_us_contact => { :email => 'test@test.com', :message => 'test' }
assigns(:contact).valid?.should eql(true)
flash[:notice].should eql('Contact email was successfully sent.')
response.should redirect_to('/')
end
+ it 'should redirect to custom URL with success message if valid contact' do
+ ContactUs.success_redirect = '/success'
+ post :create, :contact_us_contact => { :email => 'test@test.com', :message => 'test' }
+ assigns(:contact).valid?.should eql(true)
+ flash[:notice].should eql('Contact email was successfully sent.')
+ response.should redirect_to('/success')
+ end
+
it 'should render new with error message if invalid contact' do
post :create, :contact_us_contact => { :email => 'test@test.com', :message => '' }
assigns(:contact).valid?.should eql(false)
@@ -7,6 +7,7 @@
ContactUs.mailer_to = nil
ContactUs.require_name = false
ContactUs.require_subject = false
+ ContactUs.success_redirect = nil
end
it "should be valid" do

0 comments on commit fe1700c

Please sign in to comment.