Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

No route matches [PATCH] "/students.4" #22

Closed
awh112 opened this issue Jan 30, 2014 · 13 comments
Closed

No route matches [PATCH] "/students.4" #22

awh112 opened this issue Jan 30, 2014 · 13 comments

Comments

@awh112
Copy link

awh112 commented Jan 30, 2014

Anyone run into this error before? I am trying to add editing functionality but it looks like it sends me to the wrong place. I had it wired up wrong before so "Submit" just created a new student with the changes, now I get this.

Any ideas?

@awh112
Copy link
Author

awh112 commented Jan 30, 2014

Relevant code:

Controller:

  def edit
    @student = Student.find(params[:id])
  end

  def update
    @student = Student.find(params[:id])

    if @student.update(params[:student].permit(:name, :nickname, :email, :image))
      redirect_to @student
    else
      render 'edit'
    end
  end

View:

<%= form_for :student, url: student_path(@student), method: :patch do |f| %>

Index:

<td><%= link_to 'Edit', edit_students_path(student) %></td>

@awh112
Copy link
Author

awh112 commented Jan 30, 2014

Also, for some reason, I am getting an error with the back button on the error page too:

image

@jaimerump
Copy link

The "No route matching" part means that you're trying to submit the form to the wrong place or using the wrong method. You need to look at your routing table and see what it has that maps to students#update. No idea about the other error though.

@awh112
Copy link
Author

awh112 commented Jan 31, 2014

Ok well the other error was just my own fault (I had a plural instead of a non-plural for the path).

However, I was able to get the edit working by realizing that my paths were set incorrectly, and I was trying to use edit_students_path instead of just students_path.

So now, edit works, but it redirects me to a student with old data. Like, it acts really strange. If I only edit the image URL, it shows as not being edited. However, if I edit any of the other fields, it shows those changes, and sometimes the image URL changes. Overall, very erratic behavior (but when I go back to the list, the data is changed). Like, the data that is stored for the student isn't even displayed, its other random data.

Anyone see this at all?

@jaimerump
Copy link

So you're able to submit the form correctly, but the data is updated inconsistently?

@awh112
Copy link
Author

awh112 commented Jan 31, 2014

Right. It only happens if I view the page. Since the requirements called for navigating to the index, it works, but if I redirect back to the student entry, it doesn't work.

@staffordw1
Copy link

I actually just got this same error, how did you "fix" it again? I don't seem to have any routes that map to PATCH...

@awh112
Copy link
Author

awh112 commented Jan 31, 2014

So, what I ended up doing was noticing that I didn't want to go to the edit_student_path, I just wanted to go to the student_path, because on the top of my edit form I had the following:

<%= form_for :student, url: student_path(@student), method: :patch do |s| %>

I was trying to send it to the wrong form. Does that help?

@staffordw1
Copy link

I guess not... that seems to be what I have but I'm still getting that error... well, I'll keep working on it and I'll see if I can fix mine and then if it helps I'll let you know what I did. Maybe it'll fix your problem too.

@awh112
Copy link
Author

awh112 commented Jan 31, 2014

Ok. I will keep working through mine...sorry I couldn't be of more help, I changed so many lines of code when it worked I really couldn't remember what I changed to get there, I just remember taking a look at the routes and seeing what I needed to call to get the PATCH and the student#create.

@staffordw1
Copy link

Well, I managed to fix it somehow but I'm not really sure how I did it... I just sort of changed some words then changed them again and then I thought I changed them back but then it just started working so... I can't really tell you what happened, sorry :( hope you figure it out!

@rockwood
Copy link
Contributor

@awh112 were you able to figure this one out? Let me know if you're still having issues.

@awh112
Copy link
Author

awh112 commented Jan 31, 2014

I was, but in a roundabout way. As soon as I sent the user back to the index after the edit, instead of back to the individual student, it updated as expected. So, the issue was resolved, but I feel like if we were to route back to the student it would still behave erratically. I can close the issue since I am no longer have it, I just didn't know if anyone had run into the same problems. Thanks!

@awh112 awh112 closed this as completed Jan 31, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants