Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:02:46+00:00 2026-06-09T00:02:46+00:00

How to format json in rails controller? Via link_to i’m sending and get in

  • 0

How to format json in rails controller? Via link_to i’m sending and get in method params[:cat], then i fetch all childrens via parent (params[:cat]), but how to format this all in json format for my jqTree? So it looks like {label : (here goes params[:cat]), children: [{all @search_trees.id}]} ?

require 'json'
        @search_trees = SearchTree.find(:all, :include => [:designation], :conditions => { :STR_ID_PARENT => params[:cat]})
        #data = "{ label : '10001',  children : [{label : '10111'},{label : '10122'}]  }"
        respond_to do |format|
          format.html # index.html.erb
          format.xml  { render :xml => @search_trees }
          format.json { render :json => data }
        end

I’ll fetch a part of question from my long question here:

How to correctly do jquery tree in rails app?

Her is my json:

[{“search_tree”:{“STR_DES_ID”:42275,”STR_ID”:10130,”STR_ID_PARENT”:10726,”STR_LEVEL”:4,”STR_NODE_NR”:130,”STR_SORT”:621,”STR_TYPE”:1,”designation_id”:42275}},{“search_tree”:{“STR_DES_ID”:42277,”STR_ID”:10132,”STR_ID_PARENT”:10726,”STR_LEVEL”:4,”STR_NODE_NR”:132,”STR_SORT”:620,”STR_TYPE”:1,”designation_id”:42277}},{“search_tree”:{“STR_DES_ID”:43152,”STR_ID”:10730,”STR_ID_PARENT”:10726,”STR_LEVEL”:4,”STR_NODE_NR”:730,”STR_SORT”:622,”STR_TYPE”:1,”designation_id”:43152}},{“search_tree”:{“STR_DES_ID”:42209,”STR_ID”:12344,”STR_ID_PARENT”:10726,”STR_LEVEL”:4,”STR_NODE_NR”:2344,”STR_SORT”:623,”STR_TYPE”:1,”designation_id”:42209}}]
i need to output like this
jqTree – creating tree data from json

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:02:48+00:00Added an answer on June 9, 2026 at 12:02 am

    If you want to customize your json, you can use RABL or JBuilder. You will find screencasts here : http://railscasts.com/episodes/320-jbuilder?autoplay=true and here : http://railscasts.com/episodes/322-rabl?autoplay=true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why does my cfc method (when returning JSON format or called via remoting) return
I'm generating json from a Rails app, and am filtering fields using the format.json
How to convert a rails Active Records object's id:name hash object to JSON format
I'm using JSON to communicate between my rails app and iOS via RestKit (Thanks
I want void format.html response in controller in ruby on rails 3. e.g. in
In a standard Rails controller, I'd create a record like this: @user = User.new(params[:user])
I have a Rails controller with a create method, and I want to POST
I'm trying to create a user acount on my rails backend via json from
I'm having some problems posting JSON data to my rails controller and getting the
I have a Rails application where user parameters are all provided via a RESTful

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.