0

Whats the easiest way of adding custom json output when you render json? I've seen people override as_json or to_json but they usually exclude attributes or include associations. Is there a way of including plain text?

in my view:

def show_json
    show_id = URI.decode(params[:id])
    show_id = show_id.gsub(/\s*$/,'')
    logger.debug "\nshow json: #{show_id}\n"
    @qtls = Qtl.find_by_sql("select * from qtls where qtl_name like '%#{show_id}%' or qtl_symbol in (select qtl_symbol from obs_traits where qtl_symbol like '%#{show_id}%' or trait_name like '%#{show_id}%');")
    render :json => @qtls
end

this returns something like:

[{qtl: {...qtl attributes..}},{... more qtls }]

and I would like to add a a specific field for each qtl. Whats best way to do that?

1 Answer 1

1

override as_json or use some gem to provide many json templates for example https://github.com/fabrik42/acts_as_api

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you :) This feature of acts_as_api in particular I found useful if anyone is curious: github.com/fabrik42/acts_as_api/wiki/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.