Innovation Cloud - Step 14 - Receiving Error "The action 'index' could not be found for SignupsController"

Hi CC Team! I have been working through the “Innovation Cloud” project and receive the error " The action ‘index’ could not be found for SignupsController" every time I try to submit a test email address.

As you can see, the page visits /signups instead of /thanks as instructed in my code. Also, the project does not instruct me to create an index action OR view. Can you please advise?

Link to project:

Link to full question with images (Forum won’t let me post more than 1 image) :

Thank you in advance!

Hi @eternallearner_5,

That error means that Rails is looking for a function called index in signups_controller.rb. To fix it, you need to create the index function so that Rails can use it to display the view:

def index

Usually you’ll add more inside the function, maybe something like @signups = Signup.all in the body of the function, but all Rails is looking for in this case is an index function, empty or not.

Let me know if you’re still having problems after fixing that :slight_smile:

Hi @zystvan,

Thanks for helping out here. Based on the project, it doesn’t look like I should have an ‘index’ function. The problem that I’m having is that a GET request is occurring when the form is submitted (which ties to the Index controller action) instead of a POST request (which ties to the Create controller action). How can I change my code so that it runs a POST request instead of a GET request? I followed all of the steps correctly.

Thank you.

@eternallearner_5 Could you click the Share Code button along the bottom of the code editor and send me the link? I’m not sure I can help much without seeing your code in this case.

Absolutely @zystvan! Here it is:


Please let me know if I can provide anything else.

@eternallearner_5 It looks like you’re missing a name for the /thanks URL in routes.rb. When creating a resource, Rails automatically creates named routes for you (like new_signup_url or signups_url), but when you create the routes individually you need to include the name too if you want to reference it that way:

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

Since thanks_url doesn’t exist until you create it, Rails seems to be defaulting to redirecting you to the index action, rather than showing an error about thanks_url not existing.

Your other option is to leave routes.rb the way it is and change signups_controller.rb to this:

redirect_to '/thanks'

@zystvan Thanks for the suggestion. I tried both methods of setting the correct route and still run into the same issue. Could there be anything else that we can try?

@eternallearner_5 The only other guess I have right now is that the signup isn’t getting saved and so your else condition is firing. The form POSTs to /signups, so maybe Rails defaults to a GET request for /signups. Try adding a redirect to the else condition in signups_controller.rb:

  redirect_to '/thanks'
  flash[:alert] = 'User was not saved.'
  redirect_to '/thanks'

If that change makes the error go away, we’ll know what the problem is (users not being saved), and then we can try to fix that if that is the case.

@zystvan Unfortunately, that didn’t work either. Is it possible that Rails isn’t acknowledging that a POST function exists altogether?

@eternallearner_5 Not really, it’s not like Rails can “forget” how to send a post request. Do you have Ruby installed on your computer? You could try doing this project locally to see if it works any differently on your own computer. (Or send me a copy of all of your code and I can try).