2017-07-07 57 views
-4

BoardController代码:未定义方法`标题=”为#<文章ID:无,created_at:无,的updated_at:无>

BoardController

错误消息:

NoMethodError

+3

看来你的岗位模型是不是有'title'属性创建控制器的底部看到示例代码。 –

+1

Sov,请编辑您的问题,并将您的代码包含错误信息作为文本(使用代码格式)而不是使用图像。还提供更多与错误有关的信息,例如, 'Post'模型以及* schema.rb *文件中'posts'表的迁移文件或定义。 – Gerry

回答

0

这里是您的后控制器的更正

def create 
    @post = Post.new(post_params) 
    @post.save 
    redirect_to :back 
    end 

    def post_params 
    params.require(:perusahaan).permit(:title,:content) 
    end 

你应该把post_params新

,如果你没有post_params,你可以在上面

+1

尽管此代码对于控制器来说是一种更好的做法,但它不是解决问题的办法,而且会导致相同的输出(即错误)。问题是'Post'模型没有'title'属性(或者不可访问),因此'Undefined method'title''错误。 – Gerry

相关问题