Cannot access attr_accessor defined variables

前端 未结 1 1776
栀梦
栀梦 2021-01-18 12:21

I am using Thinking Sphinx to run searches and I get the appropriate ActiveRecord Models fine. The problem is, I want to create an appropriate link path and text on each mod

1条回答
  •  醉梦人生
    2021-01-18 12:42

    Rails' default to_json doesn't know about those extra non active record attributes you've added. The easiest possible thing is probably to specify them as extra methods to include:

    format.json { render :json => @results.to_json(:methods => [:search_link, :search_text]) }
    

    0 讨论(0)
提交回复
热议问题