【发布时间】:2016-11-18 17:43:25
【问题描述】:
当我想在 Rails 5 上编辑基本帖子时,simple_form 出现undefined method 'model_name' 错误。
show.html.haml:
= link_to "Edit", edit_post_path(@post)
edit.html.haml:
= simple_form_for @post do |f|
= f.input :title
= f.input :link
= f.input :description
= f.button :submit
posts_controller.rb:
def show
@post = Post.find(params[:id])
end
def edit
end
def update
if @post.update(post_params)
redirect_to @post
else
render 'edit'
end
end
有什么想法吗?
【问题讨论】:
-
控制器中有
edit操作吗? -
是的,我只是编辑我的帖子
-
将
@post = Post.find(params[:id])添加到edit操作 -
谢谢它的工作!
-
如果您发布了完整的错误消息,这将更加明显——大概是说 "...for
nil:NilClass",暗示你的@post变量是nil。
标签: ruby-on-rails ruby