Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RoR: template missing error while rendering JSON

I have the following code in my controller:

def tljson (result = [])
  @stat_id = params[:stat_id]
  @rpm = FedoraRpm.find_by_name(@stat_id)
  @rpm.ruby_gem.historical_gems.each { |h|
    result << { :content => h.version, :start => h.build_date }
    }
  @rpm.bugs.each { |b|
    result << { :content => b.name + "<br><a href='"+b.url+"'>View on BugZilla</a>", :start => b.bz_id }
  }
  @res = result.to_json
    respond_to do |format|
    format.json { render @res.to_json }
    end
end

Going to /tljson.json renders the JSON but the heading says 'Template is Missing; missing template'. What am I doing wrong?

like image 839
17andLearning Avatar asked Dec 17 '12 16:12

17andLearning


1 Answers

I believe you need to specify that you want to render :json in your respond_to block

respond_to do |format|
  format.json { render json: @res }
end

Otherwise it will look for a tljson.json.erb file.

like image 174
deefour Avatar answered Oct 04 '22 20:10

deefour