【发布时间】:2014-10-23 08:59:32
【问题描述】:
我想在我的 index.json 中添加一个修改过的变量。
views/posts/index.json.builder
json.array!(@posts) do |post|
post[:image_th] = post[:image].reverse.split('.', 2).join(".s").reverse
#this is the new line above
json.extract! post, :id, :title, :datum, :body, :image
#json.url post_url(post, format: :json)
end
所以它会在字符串中的“.jpg”之前添加一个's'。
这给出了错误:
无法写入未知属性`image_th'
如何在不创建迁移并从数据库访问它的情况下向 index.json 添加字段?
【问题讨论】:
标签: ruby-on-rails ruby json ruby-on-rails-4