代码之家  ›  专栏  ›  技术社区  ›  Liz

Rails NoMethodError for Blog在Heroku上创建,但不在本地主机上创建

  •  4
  • Liz  · 技术社区  · 6 年前

    我有一个基本博客结构的应用程序。创建新博客在 localhost 但是当我试图在Heroku上创建一个新的博客时,我的日志中会出现以下错误:

    2018-07-11T21:20:01.863867+00:00 app[web.1]: [2f20a9d7-e0f6-4ab9-b2ac-d6b3a08e8ed0] Command :: file -b --mime '/tmp/819c55b783715f61a2656207b4852b5c20180711-4-140ohfr.jpg'
    2018-07-11T21:20:01.872443+00:00 app[web.1]: [2f20a9d7-e0f6-4ab9-b2ac-d6b3a08e8ed0] Completed 500 Internal Server Error in 38ms (ActiveRecord: 0.0ms)
    2018-07-11T21:20:01.873180+00:00 app[web.1]: [2f20a9d7-e0f6-4ab9-b2ac-d6b3a08e8ed0]
    2018-07-11T21:20:01.873253+00:00 app[web.1]: [2f20a9d7-e0f6-4ab9-b2ac-d6b3a08e8ed0] NoMethodError (undefined method `[]=' for nil:NilClass):
    2018-07-11T21:20:01.873285+00:00 app[web.1]: [2f20a9d7-e0f6-4ab9-b2ac-d6b3a08e8ed0]
    2018-07-11T21:20:01.873329+00:00 app[web.1]: [2f20a9d7-e0f6-4ab9-b2ac-d6b3a08e8ed0] app/controllers/blogs_controller.rb:48:in `create'
    2018-07-11T21:20:01.874027+00:00 app[web.1]: 10.101.219.132 - - [11/Jul/2018:21:19:56 UTC] "POST /blogs HTTP/1.1" 500 1958
    2018-07-11T21:20:01.874063+00:00 app[web.1]: http://www.linchpinrealty.com/blogs/new -> /blogs
    2018-07-11T21:20:01.874816+00:00 heroku[router]: at=info method=POST path="/blogs" host=www.linchpinrealty.com request_id=2f20a9d7-e0f6-4ab9-b2ac-d6b3a08e8ed0 fwd="68.225.227.137" dyno=web.1 connect=0ms service=5463ms status=500 bytes=2235 protocol=http
    

    我的 blogs#create 方法相当简单:

     def create
        @pillars = Pillar.all
        @blog = Blog.new(blog_params)
        if current_user.id = 1
          @blog.user_id = 2
        else
          @blog.user = current_user
        end
    
        if @blog.save
          redirect_to @blog, notice: 'Blog was successfully created.'
        else
          render :new
        end
      end
    

    我有以下权限:

     private
        # Use callbacks to share common setup or constraints between actions.
        def set_blog
          @blog = Blog.friendly.find(params[:id])
        end
    
        # Only allow a trusted parameter "white list" through.
        def blog_params
          params.require(:blog).permit(:title, :teaser, :body, :user_id, :image, :tag_list, :link_text, :link_filename, :pillars_id)
        end
    

    我不确定事情的发展方向(没有双关语)。我确实看到了 this 问题:问题在哪里是数据库问题。在这种情况下,我最近所做的唯一改变就是 blogs#show 方法…即使我不知道这将如何阻止博客保存到数据库中(它不知道):

      def show
        @pillars = Pillar.all
        @pillar = Pillar.find_by(id: @blog.pillars_id)
        @related = Blog.where(pillars_id: @blog.pillars_id).where.not(id: @blog.id).limit(4)
        @comment = @blog.comments.build
        @comments = Comment.where(blog_id: @blog.id, approved: true)
        if current_user
          @user = current_user
        end
      end
    

    有人知道我哪里出错了吗?

    2 回复  |  直到 6 年前
        1
  •  1
  •   XavM    6 年前

    从日志和它在本地主机上运行良好的事实来看,托管TMP映像文件可能是一个错误。

    您应该看看这些文章:

    编辑:

    我刚看见你 get the same error without an image ,但您不设置任何默认图像吗?

    ->是否可以在不上载图像的情况下发布错误日志?

    编辑2:

    我访问了你的网站,更新了一篇现有博客文章中的图片,它可以正常工作,所以它可能没有链接到图片系统。

    EdTe3:

    在你的网站上做了一些测试后,它是 tag_list 字段错误:您可以创建一些没有标记的新博客文章,但一旦插入一些标记,就会出现错误。

    抱歉,我没有成功删除没有路由的测试

        2
  •  0
  •   Roberto Ruiz    6 年前

    你检查过Heroku上的迁移吗?