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: https://www.codecademy.com/courses/learn-rails/projects/learn-rails_innovation-cloud
Link to full question with images (Forum won’t let me post more than 1 image) : https://docs.google.com/document/d/1FSPcPg5zme2WX9dIGwUBKnvFOYMDhGm8pXwGnh-vFqk/edit?usp=sharing
Thank you in advance!
That error means that Rails is looking for a function called
signups_controller.rb. To fix it, you need to create the index function so that Rails can use it to display the view:
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
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.
@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.
@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
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'
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:
@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
flash[:alert] = 'User was not saved.'
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).