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 7898551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:27:48+00:00 2026-06-03T08:27:48+00:00

I’ve tryed the solution of following example: In Rails, how do you render JSON

  • 0

I’ve tryed the solution of following example: In Rails, how do you render JSON using a view?

But my problem is that the database already has a JSON string saved, I pull the json string and then I should be able to display the JSON file in the the view.

I’m using this because an android tablet should be able to visit the same url but depending on its settings (send by a POST) a different JSON file should be displayed, the android tablet then fetches the json and use it to configure some options.

So I already have a full working json file, i’m looking for a way to display it in a view (without rendering html tags and other stuff). I tryed the following (yes I’ve added respond_to :json) :

# def show_json (@config is the record, @config.json_config is the actual json configuration file
@config = event.et_relationships.where(terminal_id: terminal).first
respond_to do |format|
   format.json
end

Then my view I have

#show_json.json.erb
<%= @config.config_json %>

Then the HTML I get to see (no errors are given)

<html><head><style type="text/css"></style></head><body></body></html>

Thanks!

EDIT

I’m using rails 3.2.3

Here is my routes (only relevant parts)

match '/events/config', to: "events#show_json", as: :show_json
resources :events do
    member do
      get :select_item
      get :category
    end
  end

Then also the controller (partial)

respond_to :html, :json, :js
def show_json
    #terminal_id = params["mac"]
    terminal_id = "3D:3D:3D:3D:3D:3D"
    event = current_user.events.where("date(endtime) > ? AND date(starttime) < ?", Time.now.to_s, Time.now.to_s).first
    if event.nil?
      # Nothing got returned so we use the default event
      event = current_user.events.where('"default" = ?', true).first
    end
    logger.info "MAC: #{terminal_id}"
    terminal = current_user.terminals.where(serial: terminal_id).first
    logger.info "Terminal: #{terminal.attributes.inspect}"
    logger.info "#{event.attributes.inspect}"
    @config = event.et_relationships.where(terminal_id: terminal).first
    logger.info "CONFIG #{@config[:config_json]}"

    respond_to do |format|
      format.json { render json: @config[:config_json] }
    end
  end
  • 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-03T08:27:50+00:00Added an answer on June 3, 2026 at 8:27 am

    Use render:

    @config = event.et_relationships.where(terminal_id: terminal).first
    respond_to do |format|
       format.json { render json: @config }
    end
    

    And then you have path /:model/:action.json.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.