我正在尝试识别用户 ID 号,以从 ActiveRecord 表中获取学生行,但由于某种原因,“发布”块找不到我的 :id。
对于“get”,url 是 localhost:9456/update/17。正是这 17 我需要传递到“post”块来更新数据库。
我不知道该怎么做。解析网址?好像我错过了一些明显的东西。
# 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
谢谢!