我有一个基本博客结构的应用程序.创建新博客在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
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问题,问题出在数据库问题上.在这种情况下,我最近唯一的改变是在我的博客#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
谁能看到我哪里出错了?
解决方法
从日志和事实上它在本地主机上工作正常,托管您的tmp图像文件可能是一个错误.
你应该看看这些文章:
> Rails Active storage on Heroku
> Rails Active storage exemple on Heroku
编辑:
我刚刚看到你没有图像就得到了同样的错误,但是你不设置任何默认图像吗?
EDIT2:
我去了你的网站,我在现有的博客文章中更新了一个图像,它可以工作,所以它可能没有链接到图像系统.
EDIT3:
在您的网站上进行一些测试之后,这是tag_list字段是错误的:您可以创建一些没有标签的新博客文章但是只要插入一些标签就会引发错误.
Ps:对不起我没有设法在没有路由的情况下删除我的测试