I am trying to identify a user ID number, to grab a Student row from an ActiveRecord table, but for some reason the 'post' block won't find my :id.
For the 'get', the url is localhost:9456/update/17. It's this 17 I need to pass to the 'post' block to update the database.
I am not sure how to do this. Parse the URL? It seems like I am missing something obvious.
# update user page
get '/update/:id' do
@student = Student.find(params[:id]) #this returns ID=17
erb :update
end
#update user submit
post '/update' do
@student = Student.find(params[:id]) #this line doesn't work
@student.name = (params[:name])
@student.email = (params[:email])
@student.save
redirect '/'
end
thanks!
From stackoverflow
-
Are you actually passing the
idback? Are you submitting a form viaPOST? If so, all you should need to do is add an input whosenameattribute isid.<form action='/student/update' method='post'> <input type='hidden' name='id' value='17' /> </form>gleddy : thanks for that. works fine now. didn't even think about the hidden fieldTopher Fangio : No prob, any chance you could select my answer as the correct one so others know that it has a solution?
0 comments:
Post a Comment