Comments (13)
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.
Also, for some reason, I am getting an error with the back button on the error page too:
from nku.
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.
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.
So you're able to submit the form correctly, but the data is updated inconsistently?
from nku.
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.
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.
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.
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.
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.
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.
@awh112 were you able to figure this one out? Let me know if you're still having issues.
from nku.
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)
- ActiveRecord question HOT 2
- How can an administrator sign up? HOT 1
- Logout not being properly referenced HOT 1
- CSS / LESS not classes not being applied
- Adding upload action? HOT 3
- Creating an administrator HOT 3
- Question about to assignments ago, querying for assignments
- SASS Error HOT 5
- Rollback some commits HOT 5
- Question about STIs or polymorphic associations HOT 10
- Site won't collapse on mobile HOT 2
- I'm thinking about using devise HOT 4
- Who wants an invite to prelang? HOT 16
- Ruby Brigade tomorrow is anyone going?
- How do to safely use github? HOT 8
- Blank Pages HOT 5
- Can't Use Partial Dates HOT 4
- has_many :through => HOT 2
- validation errors HOT 4
- ActiveRecord::PendingMigrationError HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nku.