<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Katie Burke on Medium]]></title>
        <description><![CDATA[Stories by Katie Burke on Medium]]></description>
        <link>https://medium.com/@katherine89?source=rss-f19a91fc3ef4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZUeXSjuhGOj0K59P6papGQ.jpeg</url>
            <title>Stories by Katie Burke on Medium</title>
            <link>https://medium.com/@katherine89?source=rss-f19a91fc3ef4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 19:25:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@katherine89/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating an Ember and Rails app with a POST request for side project RemoteVibes]]></title>
            <link>https://medium.com/ar-vr-journey/creating-an-ember-and-rails-app-with-a-post-request-for-a-side-project-c89834e82031?source=rss-f19a91fc3ef4------2</link>
            <guid isPermaLink="false">https://medium.com/p/c89834e82031</guid>
            <category><![CDATA[augmented-reality]]></category>
            <category><![CDATA[ember]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[virtual-reality]]></category>
            <dc:creator><![CDATA[Katie Burke]]></dc:creator>
            <pubDate>Tue, 02 Oct 2018 12:29:43 GMT</pubDate>
            <atom:updated>2018-11-02T21:40:30.592Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tb6NosW_okoGRI9OOXIf0w.jpeg" /></figure><p>This post is a tutorial that will go through creating a simple app with ember js on the front-end and ruby on rails on the back-end.</p><p>I am working on a side project called RemoteVibes and I am going to do tutorials of parts of creating the app as I go along.</p><p>RemoteVibes is a project management tool for software developers working on remote teams.</p><p>This tutorial will go through setting up the app and doing a POST request.</p><h3>Trending AR VR Articles:</h3><blockquote><a href="https://arvrjourney.com/ready-player-one-how-close-are-we-8af973c1cfa0">1. Ready Player One : How Close Are We?</a></blockquote><blockquote><a href="https://arvrjourney.com/challenges-of-ar-market-in-early-2018-957f19cb103f">2. Challenges of AR Market in early 2018</a></blockquote><blockquote><a href="https://arvrjourney.com/augmented-reality-with-react-native-15219f36e3f2">3. Augmented Reality — with React-Native</a></blockquote><p>Firstly let’s check what versions we are using:</p><pre>ruby -v</pre><p>&gt;ruby 2.5.1p57</p><pre>rails -v</pre><p>&gt;Rails 5.2.1</p><p>Ember version: “2.14.1”</p><p>Let’s create a new Ember app:</p><pre>ember new work-vibes-projects-frontend</pre><pre>cd work-vibes-projects-frontend</pre><p>Let’s do:</p><pre>ember serve</pre><p>Let’s add code to the application.hbs file:</p><pre>&lt;div&gt; Welcome to Work Vibes Front-end App! :) &lt;/div&gt;</pre><p>You should now see that when you load the webpage!</p><p>Now let’s add a users route to the file router.js:</p><pre>//app/router.js<br>Router.map(function() {<br> this.route(‘users’);<br>});</pre><p>Now let’s add a users route:</p><pre>ember generate route users</pre><p>We now have a file called users.js and users.hbs</p><p>Let’s add the following code to application.hbs:</p><pre>{{outlet}}</pre><p>and add this code to users.hbs:</p><pre>&lt;div&gt;Users page&lt;/div&gt;</pre><p>You should now see that line added when you go to <a href="http://localhost:4200/users">http://localhost:4200/users</a></p><p>Let’s add a button to create a new user in users.hbs:</p><pre>&lt;button {{action “createUser” “Katie” “<a href="/service/mailto:katie@gmail.com">katie@gmail.com</a>”}}&gt; Create a new user &lt;/button&gt;</pre><p>Let’s create the corresponding action in the route file that prints “Create user” with the following code:</p><pre>//app/routes/users.js<br>export default Route.extend({<br>  actions: {<br>    createUser(name, email) {<br>      console.log(&quot;Create user&quot;);<br>    }<br>  }<br>});</pre><p>When the button is clicked we should see Create user logged in the javascript console.</p><p>Now let’s add the post request:</p><pre>//app/routes/users.js<br>let user = this.get(“store”).createRecord(“user”, {<br> name: name,<br> email: email<br>});<br>user.save();</pre><p>I get an error when I click the button which says:</p><p>Uncaught TypeError: Cannot read property ‘create’ of undefined</p><p>We need to create a User model.</p><pre>ember generate model user</pre><p>Let’s add the info to the model:</p><pre>//app/models/user.js<br>export default DS.Model.extend({<br>  name: DS.attr(&quot;string&quot;),<br>  email: DS.attr(&quot;string&quot;)<br>});</pre><p>Now when we click the createUser button we get a 404 error which is what we expect because we haven’t written the back-end code yet.</p><p>Let’s create our rails api and write the backend!</p><pre>cd ..</pre><pre>rails new work_vibes_projects_api — api</pre><pre>cd work_vibes_projects_api</pre><p>Let’s open up the routes.rb file and add the following line:</p><pre>Rails.application.routes.draw do<br> resources :users<br>end</pre><p>Let’s generate a users controller:</p><pre>rails generate controller users</pre><p>Let’s add the following code to the controller:</p><pre>class UsersController &lt; ApplicationController<br>  protect_from_forgery<br>  # POST /users<br>  def create<br>    user = User.create!(user_params)<br>    if user.save<br>      render jsonapi: user<br>    else<br>      render jsonapi_errors: user.errors<br>    end<br>  end<br>  private<br>  def user_params<br>    # whitelist params<br>    params.require(:_jsonapi)<br>    .require(:data)<br>    .require(:attributes)<br>    .permit(:name, :email)<br>  end<br>end</pre><p>We will be using a gem called jsonapi-rails, let’s install it:</p><p>Add the following to your application’s Gemfile:</p><pre>gem ‘jsonapi-rails’</pre><p>And then execute:</p><pre>bundle install</pre><p>Now let’s try to run our ember app and rails app together add see what happens.</p><p>let’s run the following line in the front-end folder:</p><pre>ember serve — proxy <a href="http://tcp//0.0.0.0:3000">http://tcp://0.0.0.0:3000</a></pre><p>and run the following in the back-end folder:</p><pre>rails server</pre><p>Now when I click the CreateUser button I get a 400 error that says (Empty Content-Type).</p><p>The front-end is not sending the data in the correct format for jsonapi.</p><p>I need to add an Adapter and a Serializer on the front-end.</p><p>Let’s add an adapters folder and add the file applicaion.js</p><p>It should look like this:</p><pre>//app/adapters/application.js<br>import DS from &quot;ember-data&quot;;<br>export default DS.JSONAPIAdapter.extend({<br>  host: &quot;<a href="http://localhost:3000/">http://localhost:3000</a>&quot;,<br>  dataType: &quot;json&quot;<br>});</pre><p>Let’s also add a serlializers folder and the file application.js with the following content:</p><pre>// app/serializers/application.js<br>import DS from “ember-data”;<br>export default DS.JSONAPISerializer.extend({});</pre><p>Now I’m getting the following error:</p><p><em>Response for preflight has invalid HTTP status code 404.</em></p><p>This is related to CORS.</p><p>Let’s create the file /initializers/cors.rb to have the following code:</p><pre>Rails.application.config.middleware.insert_before 0, Rack::Cors do<br>  allow do<br>    origins &#39;example.com&#39;</pre><pre>resource &#39;*&#39;,<br>      headers: :any,<br>      methods: [:get, :post, :put, :patch, :delete, :options, :head]<br>  end<br>end</pre><p>And restart the server.</p><p>Now when I click the button I get a 500 error because we have no user model.</p><p>Let’s create a user model on the back-end.</p><pre>rails generate model user name:string email:string</pre><p>Let’s run:</p><pre>rails db:migrate</pre><p>Now I get a different 500 error.</p><p>We need a serializable folder on the back-end anyway, with the file serializable_user.rb</p><p>The file should have the following code:</p><pre>class SerializableUser &lt; JSONAPI::Serializable::Resource<br>  type &#39;users&#39;</pre><pre>attributes :name, :email<br>end</pre><p>After restarting the server and clicking the button to create a user I am now getting a 200 which means success.</p><p>Let’s check if the user was saved to the database by running:</p><pre>rails console</pre><p>and doing:</p><pre>User.last</pre><p>This shows the user that was saved in the database.</p><p>The next step would be to add two input boxes with the name and email fields and save them.</p><p>The next blog post will show how to do a simple relationship between two models with ember and rails.</p><figure><a href="https://docs.google.com/forms/d/1YBHAY792wL3OslxTQRqcIbRICNeKdeYSiSr2HyVrptU/edit"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*Wt2auqISiEAOZxJ-I7brDQ.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c89834e82031" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ar-vr-journey/creating-an-ember-and-rails-app-with-a-post-request-for-a-side-project-c89834e82031">Creating an Ember and Rails app with a POST request for side project RemoteVibes</a> was originally published in <a href="https://medium.com/ar-vr-journey">AR/VR Journey: Augmented &amp; Virtual Reality Magazine</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>