2017-07-20 87 views
0

更新方法似乎沒有工作,我得到的錯誤如下:我無法使用更新方法的原因是什麼?

Started PATCH "/lessons/4" for 127.0.0.1 at 2017-07-20 11:23:27 +0900 
Processing by LessonsController#update as HTML 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"+95AUkvSbAUfVzAp9xweeiuq8IKq3gdqJB5oP8HoRP3NvkoYHkGRYe1TQSMxVtTZGPlATx6ltb0SThD6ifMXpg==", "lesson"=>{"title"=>"まずはじめに", "content"=>"Jelly beans chupa chups soufflé toffee cookie croissant sugar plum cookie. Danish caramels gummi bears marzipan apple pie cupcake jelly pudding dragée. Jelly-o pastry halvah sweet. Pudding jujubes marshmallow pie soufflé. Tart chocolate bar dragée bonbon cotton candy jelly beans chupa chups. Cheesecake tart chupa chups candy canes sweet roll biscuit candy lollipop. Chupa chups lemon drops chocolate bear claw muffin tiramisu pastry marzipan ice cream. Sweet candy canes danish halvah caramels cupcake donut lemon drops gummi bears."}, "commit"=>"更新", "id"=>"4"} 
    Lesson Load (0.1ms) SELECT "lessons".* FROM "lessons" WHERE "lessons"."id" = ? LIMIT ? [["id", 4], ["LIMIT", 1]] 
    User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]] 
No template found for LessonsController#update, rendering head :no_content 
Completed 204 No Content in 112ms (ActiveRecord: 0.3ms) 

我有一個課程模式和課程模式,我可以使用更新方法爲我場模型而不是課模型...

有什麼建議嗎?

+0

請上傳LessonController, – widjajayd

回答

2

這爲我工作,希望,就必須對你來說,如果它保存在DB

def update 
@lesson = Lesson.find(params[:id]) 
if @lesson.update(params) 
    redirect_to root_path, alert: "Your lesson is saved!" 
else 
    render 'edit', alert: "Oops! There was a problem, please try again" 
end 
end 
+0

謝謝!它的工作要做! – Robert

+0

@Robert最受歡迎 –

相關問題