【发布时间】:2013-07-23 19:35:38
【问题描述】:
我是 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 %>
当我想更新任何帖子时,我不断收到此错误:
PostsController#update 中的 NoMethodError
nil:NilClass 的未定义方法“更新”
任何帮助将不胜感激! :)
【问题讨论】:
-
请在 before_filter 中设置@post。
-
new syntax 的
before_filter现在是before_action
标签: ruby-on-rails ruby