launchscout / nku

NKU Class Spring
5 stars 14 forks source link

New Issue 'No Route Matches Post' #21

Closed staffordw1 closed 10 years ago

staffordw1 commented 10 years ago

I'm pretty sure this is something super simple that I'm missing but I can't seem to pinpoint exactly what after trying a bunch of different things. Here's my error:

screen shot 2014-01-30 at 4 55 23 pm

So this occurs after the user enters their info and hits the submit button. Here's the code I've been using for my create method:

screen shot 2014-01-30 at 4 56 09 pm

From googling I think I've determined what the problem isn't. It's not that 'StudentsController' is named 'StudentController'. Adding the code in routes.rb: post "students/create" changes nothing. Adding: post "students/new" just takes them back to the form they just filled out, but doesn't post it. Adding: post "student/index" makes everything worse.

I don't really know what else to try but I have been just changing tiny bits of code to try to make it work but nothing seems to change...

jaimerump commented 10 years ago

I think you have the code for your form messed up. Right now it's trying to POST to students/new. To trigger the create action, according to that routing table it needs to POST to students. Your form is just posting to the wrong url, either because you don't explicitly pass one in when you define the form, or because you're passing the wrong one in.

staffordw1 commented 10 years ago

Yep, that seems to have been exactly what the issue was, I knew it was going to be something painfully simple... changing url: new_students_path to just students_path takes me to a page listing the info entered and displaying the image. I guess now I should just add a link back to the student list from there? Or is there a way to just take the user right back to the list and post it?

staffordw1 commented 10 years ago

Ah nevermind, I'm pretty sure this is what I want it to do anyways, thanks @jaimerump for helping me out again, I really appreciate it!

jaimerump commented 10 years ago

Instead of redirect_to @student, you could redirect to students_path or students_index_path to get back to the list. Also, are you using a view partial for the form? If so, your solution might cause issues with submitting the edit form, since students#update requires a PUT to a different path. If you're hardcoding the forms into the views, your solution will work fine.

staffordw1 commented 10 years ago

Nah, I'm hardcoding the forms into views. Yeah, doing what you said seems to work, thanks again!!