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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:34:59+00:00 2026-06-10T05:34:59+00:00

I finished Ryan Bates #348 video for creating a JSON API using the rails-api

  • 0

I finished Ryan Bates #348 video for creating a JSON API using the rails-api gem. I have it working as in the example. However, in his example he has the page that calls the API in the same project. My goal is to separate out the client app from the API app.

I created a second rails app that simply includes the page that does a JSON request for the API data and a post when submitting the form. I have the client app running on localhost:3000 and the API running on localhost:4000.

Below is the client side code. It successfully submits a new deal record, but the
GET doesnt load the list of deals. When looking in the logs it appears it is requesting it as HTML. When the page was apart of the same API project, the same code was making the call as JSON in the logs.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
  $(function() {
    function addDeal(deal) {
      $('#deals').append('<li>' + deal.name + '</ul>');
    }

    $('#new_deal').submit(function(e) {
      $.post('http://localhost:4000/deals', $(this).serialize(), addDeal);
      this.reset();
      e.preventDefault();
    });

    $.getJSON('http://localhost:4000/deals', function(deals) {
      $.each(deals, function() { addDeal(this); });
    });
  });
</script>

<div id="container">
  <h1>My Deals</h1>
  <form id="new_deal">
    <input type="text" name="deal[name]" id="deal_name">
    <input type="submit" value="Add">
  </form>
  <ul id="deals"></ul>
</div>
  • 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-10T05:35:00+00:00Added an answer on June 10, 2026 at 5:35 am

    Because of Cross Origin Policy you have following options:

    1. Use jsonp (don’t do this since you have your server 🙂 check below )
    2. Manage Cross Origin Resource Sharing on server, recently I wrote answer here how to achieve this
    3. You could use rails ActiveResource::Base to conect to your api, but it may be slow, and you would repeating yourself unless there is some presentation logic you need on backend. BTW, check Nibbler gem it may be somewhat better… it really depends what you need to do in backend.

    Anyhow. I would avoid approach 1, its kinda overhead especially if you want to POST, PUT or DELETE, and you can allows use option 2 if you have pure javascript app running as UI. But even if you are building JS agnostic app you always need a bit of backend processing so option 3 is probably something you’d prefer.

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

Sidebar

Related Questions

Just finished the Django tutorial. Starting my own project. Using the ManyToMany Relationship example
I finished the English version of my application and now I am working on
Almost finished my java web app. All working fine. Whats next. I need now
Just finished up my first mvc4 app. Everything is working great until I deploy
I finished my small application and I am trying to make sure I have
I have just finished watching the following videos in an attempt to understand JDO
I finished the tutorial on Django's site about using mod_wsgi ( here ), and
I finished my course on Oracle databases and have been playing with it since
I have just finished building a website for client, instantinteriors.com.au . (Visit this site
I just finished my website, using codeigniter, i uploaded the site to a bluehost

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.