Step 13 Can't get form to redirect to thanks_url


#1

Instructions step 13:
"In the Signups controller, make an action named create. Use signup_params to safely collect data from the form and update the database. After saving to the database, redirect to thanks_url. "

My issue:
In the app, everything in the form is working, except the redirect. After I enter en email, it saves to the db but doesn’t redirect to thanks_url. There is a thanks.erb.html page in the views that is provided with pre written code, I believe it is the one I’m supposed to be redirecting to. Here’s my code in the signups_controller:

class SignupsController < ApplicationController
  def new
    @signup = Signup.new
  end
  
  def create 
    @signup = Signup.new(signup_params) 
    @signup.save 
    redirect_to 'thanks_url'
  end
  
  private
  def signup_params
    params.require(:signup).permit(:email)
  end
end

Or, maybe there is an error in my routes.rb file. Here is my code:

Rails.application.routes.draw do
  root 'signups#new'
  get '/thanks' => 'thanks#Pages'   
  resources :signups
end

And here is the code that was provided in the views for the thanks.erb.html page:

<div class="header">
  <div class="container">
    <h1>Thanks.</h1>
    <p>We'll keep you posted.</p>
  </div>
</div>

#2

Hi @chel7,

In your config/routes.rb file, you need to specify that you want /thanks to be called thanks. Also, the controller name should come before the method (controller#method). Try modifying line 3 to look like this instead:

get '/thanks' => 'pages#thanks', as: :thanks

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.