I have create a show method in tour controller and want to render the data from the database into json format. This the definition of the tour controller
class ToursController < ApplicationController
respond_to :json
def show
@tourcategory = Tourcategory.find(params[:id])
@tours= @tourcategory.tours
@tourcategories = Tourcategory.all
render :layout => false
end
end
This is the definition of the show.html.haml view
%h3 Tour for #{@tourcategory.title}
= @tours.to_json
The output of this code is following:
[{"content":"dscfds","created_at":"2015-12-12T09:48:32Z","elementid":"test1","id":8,"jobid":2,"next_button_title":"next","priority":23,"title":"test1","updated_at":"2015-12-12T09:48:32Z"}]
But i just want to render the data in this kind of json format, following:
var tour = {
id: "tour",
steps: [
{
title: "abc",
content: "Click this Button.",
target: "#abc",
placement: "bottom",
showNextButton: false,
skipIfNoElement : true
},
Aucun commentaire:
Enregistrer un commentaire