<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nathaniel</title>
    <description>The latest articles on DEV Community by Nathaniel (@nathaniel_cowan).</description>
    <link>https://dev.to/nathaniel_cowan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F663243%2F33b1e676-675a-44fc-9faf-9565e8d8f4d8.jpeg</url>
      <title>DEV Community: Nathaniel</title>
      <link>https://dev.to/nathaniel_cowan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nathaniel_cowan"/>
    <language>en</language>
    <item>
      <title>Flatiron | In the Deep End</title>
      <dc:creator>Nathaniel</dc:creator>
      <pubDate>Sat, 27 Nov 2021 06:24:37 +0000</pubDate>
      <link>https://dev.to/nathaniel_cowan/flatiron-in-the-deep-end-50o9</link>
      <guid>https://dev.to/nathaniel_cowan/flatiron-in-the-deep-end-50o9</guid>
      <description>&lt;p&gt;Hooray, I did it! This is my last project with Flatiron. For the last several months my life has been consumed in code, tearing into projects. Now is the time to apply all my newly acquired skills and complete the course and begin my career as a software engineer.&lt;/p&gt;

&lt;p&gt;Learning the coursework was like drinking water from a firehouse. It all comes at once and at times can be a lot to handle. After careful review, confusing subjects became clarified and gave me a newfound appreciation of the work that has gone into programming.&lt;/p&gt;

&lt;p&gt;Before Flatiron I had no programming experience. Now I know how to create full stack applications. It’s amazing what can happen in only a few short months.&lt;/p&gt;

&lt;p&gt;I realize with this final project just how far I’ve come from day one. Learning to program has in many ways been like learning to swim. On day one I could barely float.  I couldn’t imagine creating a website frontend. Now, I’m making application with both a frontend and backend&lt;/p&gt;

&lt;p&gt;While this article signals the end of my time as a Flatiron student. The field of programming is vast and I have only scratched the surface of what there is to know. There will be obstacles along the way, but Flatiron has taught me how to overcome them. So when rough times head my way, I will be able to keep my chin up and take it on, like a true programmer.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JS RoR Project</title>
      <dc:creator>Nathaniel</dc:creator>
      <pubDate>Wed, 07 Jul 2021 19:31:00 +0000</pubDate>
      <link>https://dev.to/nathaniel_cowan/js-ror-project-3m17</link>
      <guid>https://dev.to/nathaniel_cowan/js-ror-project-3m17</guid>
      <description>&lt;p&gt;This blog is about my latest project here in Flatiron. It was my first experience with JavaScript and I have to say, I like it! This was a challenge to learn, but I now have a newfound appreciation of the language and take pride in being able to write JavaScript like the programmers I look up to.&lt;/p&gt;

&lt;p&gt;For this project, I decided I wanted to achieve a few things:&lt;/p&gt;

&lt;p&gt;Reinforce old knowledge&lt;br&gt;
Meet the requirements for the project&lt;br&gt;
Push myself&lt;/p&gt;

&lt;p&gt;The Problem&lt;br&gt;
A trading card game I play consists of many different pieces and it's hard to keep everything straight. The sheer size of the game intimidates a lot of people. I wanted to implement a solution that would help other people build and rank cards for decks, based on that creature's abilities.&lt;/p&gt;

&lt;p&gt;Data Model&lt;br&gt;
An important part about a project is the data model. The model below shows my has_many and belongs_to relationship.&lt;/p&gt;

&lt;p&gt;Creatures(parent)   Skill(child)&lt;/p&gt;

&lt;p&gt;Rails&lt;/p&gt;

&lt;p&gt;I used Active Model Serializers to transfer data with json.&lt;/p&gt;

&lt;p&gt;class CreatureSerializer&lt;br&gt;
  include FastJsonapi::ObjectSerializer&lt;br&gt;
  attributes :name, :image, :description, :skills&lt;br&gt;
end&lt;/p&gt;

&lt;p&gt;Above you see the attributes name, image, description, likes, and skills for the Creature database.&lt;/p&gt;

&lt;p&gt;I also found that in order to render the correct routes I had to make a change in my config&amp;gt;initializers&amp;gt;cors.rb file.&lt;br&gt;
Rails.application.config.middleware.insert_before 0, Rack::Cors do&lt;br&gt;
  allow do&lt;br&gt;
    origins '*'&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource '*',
  headers: :any,
  methods: [:get, :post, :put, :patch, :delete, :options, :head]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;end&lt;br&gt;
end&lt;/p&gt;

&lt;p&gt;This is the final result.&lt;br&gt;
    {&lt;br&gt;
      "id": "4",&lt;br&gt;
      "type": "creature",&lt;br&gt;
      "attributes": {&lt;br&gt;
        "name": "Creature Name",&lt;br&gt;
        "image": "Creature Image",&lt;br&gt;
        "description": "Creature Description",&lt;br&gt;
        "likes": "0",&lt;br&gt;
        "skills": [&lt;br&gt;
          {&lt;br&gt;
            "id": 86,&lt;br&gt;
            "name": "Creature Skill",&lt;br&gt;
            "creature_id": 4,&lt;br&gt;
            "created_at": "2021-06-10T15:20:17.399Z",&lt;br&gt;
            "updated_at": "2021-06-10T15:20:17.399Z"&lt;br&gt;
          }&lt;br&gt;
        ]&lt;br&gt;
      }&lt;/p&gt;

&lt;p&gt;JS&lt;/p&gt;

&lt;p&gt;I then worked on building my JavaScrpt objects. My main class was Creature as seen below:&lt;/p&gt;

&lt;p&gt;class Creature {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static allCreatures = []

constructor(creature){
    this.id = creature.id
    this.name = creature.attributes.name
    this.image = creature.attributes.image
    this.description = creature.attributes.description
    this.likes = creature.attributes.likes
    this.skills = creature.attributes.skills
    Creature.allCreatures.push(this)
    this.renderCreature()
}

static renderCreatures(creatures){
    card.innerHTML = ""
    for(let c of creatures){
        c.renderCreature()
    }
}

static fetchCreatures(){
    fetch(creaturesURL)
    .then(response =&amp;gt; response.json())
    .then(creatures =&amp;gt; {
        for( let c of creatures.data){
            let newCreatureCard = new Creature(c)
        }
    })
}


renderCreature(){
    const creatureLi = document.createElement('li')
    const h2 = document.createElement('h2')
    const img = document.createElement('img')
    const p = document.createElement('p')
    const creaturesSkills = document.createElement('ul')

    const likeCount = document.createElement('p')
    const likeButton = document.createElement('button')

    const deleteButton = document.createElement('button')
    const skillForm = document.createElement('form')
    creatureLi.dataset.id = this.id
    card.appendChild(creatureLi)
    h2.innerText = this.name
    img.src = this.image
    img.width = 200
    p.innerText = this.description
    likeCount.innerText = this.likes
    likeButton.innerText = "Like"
    likeButton.addEventListener("click", this.addLikes)
    deleteButton.innerText = "Delete"
    deleteButton.addEventListener("click", this.deleteCreature)
    skillForm.innerHTML =`
    &amp;lt;input type="text" placeholder="Add Skill"&amp;gt;
    &amp;lt;input type="submit"&amp;gt;
    `
    skillForm.addEventListener("submit", Skill.createSkill)
    creaturesSkills.dataset.id = this.id
    this.skills.forEach(skill =&amp;gt; {
        let newSkill = new Skill(skill)
        newSkill.renderSkill(creaturesSkills)
    })
    creatureLi.append(h2, img, p, creaturesSkills, skillForm, likeCount, likeButton, deleteButton)
}

static submitCreature(event){
    event.preventDefault()
    fetch(creaturesURL, {
        method: "POST",
        headers: {
            "Content-Type":"application/json",
            "Accept":"application/json",
        },
        body: JSON.stringify({
            name: enterCreatureName.value,
            image: enterCreatureImage.value,
            description: enterCreatureDescription.value,
            likes: enterCreatureLikes.value
        })
    })
    .then(res =&amp;gt; res.json())
    .then(creature =&amp;gt; {
        let newCreature = new Creature(creature.data)
        makeACreature.reset()
    })
}

deleteCreature(){
    const creatureId = this.parentElement.dataset.id
    fetch(`${creaturesURL}/${creatureId}`,{
        method:"DELETE"
    })
    this.parentElement.remove()
}

addLikes(e){
    e.preventDefault()
    let more = parseInt(e.target.previousElementSibling.innerText) + 1
    const creatureId = this.parentElement.dataset.id
    console.log(e.target.previousElementSibling)
    fetch(`${creaturesURL}/${creatureId}`, {
        method: "PATCH",
        headers: {
            "Content-Type": "application/json",
            "Accept": "application/json"
        },
        body: JSON.stringify({
            "likes": more
        })
        })
      .then(res =&amp;gt; res.json())
      .then((like_obj =&amp;gt; {
        e.target.previousElementSibling.innerText = `${more} likes`;
      }))
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;I used iterators and JQuery to process data and append to the DOM. Once this was completed I had my final product.&lt;/p&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;This was a challenging but rewarding lesson.I am grateful to have had the chance to further develop my knowledge of rails as well get the opportunity to learn JavaScript.&lt;/p&gt;

&lt;p&gt;This JavaScript portion was a challenge. I had no previous experience with this language, but I am grateful to have learned this skill and look forward to further developing my knowledge of it!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
