Coder Social home page Coder Social logo

Comments (13)

awh112 avatar awh112 commented on September 1, 2024

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>

from nku.

awh112 avatar awh112 commented on September 1, 2024

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

image

from nku.

jaimerump avatar jaimerump commented on September 1, 2024

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.

from nku.

awh112 avatar awh112 commented on September 1, 2024

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?

from nku.

jaimerump avatar jaimerump commented on September 1, 2024

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

from nku.

awh112 avatar awh112 commented on September 1, 2024

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.

from nku.

staffordw1 avatar staffordw1 commented on September 1, 2024

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...

from nku.

awh112 avatar awh112 commented on September 1, 2024

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?

from nku.

staffordw1 avatar staffordw1 commented on September 1, 2024

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.

from nku.

awh112 avatar awh112 commented on September 1, 2024

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.

from nku.

staffordw1 avatar staffordw1 commented on September 1, 2024

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!

from nku.

rockwood avatar rockwood commented on September 1, 2024

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

from nku.

awh112 avatar awh112 commented on September 1, 2024

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!

from nku.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.