我是
Ruby on Rails和堆栈溢出的初学者.很抱歉,如果在提出这个问题时有错误或……
我正在尝试为我的博客项目编写编辑/更新.这是我的控制器:
- def edit
- @post = Post.find params[:id]
- end
- def update
- @post.update(params[:post].permit(:title,:summary,:content))
- redirect_to posts_path
- end
这是我的看法:
- <h1>Edit Page</h1>
- <%= form_for @post do |f| %>
- Title: <%= f.text_field :title %>
- Summary: <%= f.text_area :summary %>
- Content: <%= f.text_area :content %>
- <%= f.submit "Update" %>
- <% end %>
当我想更新任何帖子时,我不断收到此错误:
NoMethodError in PostsController#update
undefined method `update’ for nil:NilClass
任何帮助将不胜感激!