当我想编辑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
有什么想法吗?
答案 0 :(得分:0)
def edit
@post = Post.find(params[:id]) # <=========
end