在Rails上使用ruby的systemStackError

时间:2018-07-10 09:43:46

标签: ruby-on-rails ruby backend server-side

我使用Rails 5上的ruby创建了一个小项目。我想为显示论文记录创建索引页。所以我写道:

def index
    respond_to do |format|
      format.html 
      format.json {
       render :json => Thesis.all
      }
    end
end

此方法应显示论文记录(例如html和json),但像html一样,当我询问从puma服务器收到的localhost:3000 / theses.json时,此错误:

SystemStackError (stack level too deep):

app/controllers/theses_controller.rb:12:in `block (2 levels) in index'
app/controllers/theses_controller.rb:9:in `index'

您对此错误有任何想法吗?

这是我的论文模型:

class Thesis < ApplicationRecord
  has_many_attached :img  
end

谢谢。

1 个答案:

答案 0 :(得分:0)

模型中的属性是错误的:has_many意味着可以有很多图像,但是参数'img'意味着只能有一个图像。该错误属于ActiveStorage,并且在附加的引用名称与model属性相同时引发。

使用下一步解决此错误:

has_many_attached :imgs #for multiple images
has_one_attached :img #for one image per object
相关问题