I have a model let's say Student and I want to edit a row in the table
name students through Ajax after clicking a button, what is the correct
way to do this? Also, please note I want to edit value inside one column
followers
Not sure what you are asking. Are you asking how to perform the
action in the controller when it receives the POST? If not then
please try to explain again exactly what the question is. Also say
what you have already tried.
First, as bala kishore pulicherla said, you should be using PUT rather
than POST. Second, though, you also need to tell Rails *which*
student to update. So, rather than /students/, it should be
/students/42 or whatever.
I tried with URL "/students/1", which is obviously for editing the
Student with id 1, but with type: "POST" the URL returns 404 error in
the console. So, I tried with type: "PUT", the URL here doesn't return
the 404 error but it doesn't update the Student.
Dave Aronson, consulting software developer of Codosaur.us,
PullRequestRoulette.com, Blog.Codosaur.us, and Dare2XL.com.
I tried with URL "/students/1", which is obviously for editing the
Student with id 1, but with type: "POST" the URL returns 404 error in
the console. So, I tried with type: "PUT", the URL here doesn't return
the 404 error but it doesn't update the Student.
Also, I have double checked the field I'm gonna update i.e, var
dataString = "student[followers]=5";
Respectful of all that have offered here, I would like to ask for a little more information. Please post here your View (…html.erb) , the relevant view that contains class clap, and the controller underlying that view. And then run rake routes, and provide that result.
Thanks, Liz
Are you using the stock-standard generator-generated routes and
controller? Can you "puts" something in the controller's update
action to confirm that you are indeed reaching the correct action?
That would solve as much of it as we can with the information already
given. If you are reaching the right controller action but the
desired updating is not happening, we'll need to see the code in the
controller action.