<?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 Aliciea Dawn Suechin on Medium]]></title>
        <description><![CDATA[Stories by Aliciea Dawn Suechin on Medium]]></description>
        <link>https://medium.com/@alicieadawnr?source=rss-8ab8e7e49990------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*BZuDfX8BxJ6_CqM-.jpg</url>
            <title>Stories by Aliciea Dawn Suechin on Medium</title>
            <link>https://medium.com/@alicieadawnr?source=rss-8ab8e7e49990------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:15:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alicieadawnr/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[How Fetches works]]></title>
            <link>https://medium.com/@alicieadawnr/how-fetches-works-3fbb831e7e22?source=rss-8ab8e7e49990------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fbb831e7e22</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Aliciea Dawn Suechin]]></dc:creator>
            <pubDate>Wed, 04 Sep 2019 04:13:00 GMT</pubDate>
            <atom:updated>2019-09-04T04:13:00.882Z</atom:updated>
            <content:encoded><![CDATA[<p>DOM MANIPULATION, addEventListeners, document.createElement, selectors and .innerHTML</p><pre>document.addEventListener(&#39;DOMContentLoaded&#39;, function() {   <br>const imageId = 72 //Enter your assigned imageId here  <br>const imageURL = `https://randopic.herokuapp.com/images/${imageId}`  const likeURL = `https://randopic.herokuapp.com/likes/`  <br>const commentsURL = `https://randopic.herokuapp.com/comments/`  const image = document.getElementById(&quot;image&quot;)  <br>const imageName = document.getElementById(&#39;name&#39;)  <br>const likes = document.getElementById(&quot;likes&quot;)  <br>const like_button = document.getElementById(&quot;like_button&quot;)  <br>const commentForm = document.getElementById(&quot;comment_form&quot;)  <br>const comments = document.getElementById(&quot;comments&quot;)  <br>const commentInput = document.getElementById(&quot;comment_input&quot;)   </pre><pre>fetch(`${imageURL}`)  <br>.then(res=&gt; res.json())  <br>.then(data =&gt; {    <br>image.setAttribute(&quot;src&quot;,`${data.url}`)    data.comments.sort(function(a, b){return b.id - a.id}).forEach((comment)=&gt; {      comments.prepend(createComment(comment))    <br>})    <br>likes.innerText = data.like_count    <br>imageName.innerText = data.name  })//end fetch   like_button.addEventListener(&#39;click&#39;,() =&gt; {      <br>likes.innerText = parseInt(likes.innerText) +1      fetch(`${likeURL}`, {        <br>method: &quot;POST&quot;,        <br>headers: {&#39;Accept&#39;: &#39;application/json&#39;,                <br>&#39;Content-Type&#39;: &#39;application/json&#39;},        <br>body: JSON.stringify({          <br>image_id: `${imageId}`,          <br>like_count: `${likes.innerText}`})      <br>}).then(res=&gt; res.json())<br>//end fetch   <br>})</pre><pre>//end button event listener   <br>commentForm.addEventListener(&#39;submit&#39;, (event) =&gt; {    event.preventDefault();     <br>fetch(`${commentsURL}`, {      <br>method: &quot;POST&quot;,      <br>headers: {&#39;Accept&#39;: &#39;application/json&#39;,              <br>&#39;Content-Type&#39;: &#39;application/json&#39;},      <br>body: JSON.stringify({        <br>image_id: `${imageId}`,        <br>content: `${commentInput.value}`      <br>})    <br>}).then(res =&gt; res.json())    <br>.then(comment =&gt; {    <br>comments.append(createComment(comment))    <br>})    <br>commentForm.reset() <br> }) <br>comments.addEventListener(&#39;click&#39;, () =&gt; {    <br>if (event.target.hasAttribute(&#39;data-id&#39;)){      <br>let parentLi = event.target.parentNode      fetch(`https://randopic.herokuapp.com/comments/${event.target.getAttribute(&#39;data-id&#39;)}`, {        <br>method: &quot;DELETE&quot;      <br>}).then(res =&gt; res.json())      <br>.then(data =&gt; window.alert(&quot;comment deleted&quot;))      parentLi.remove()    }}) <br>})//end DOM content loaded <br>function createDeleteButton(comment){  <br>let delete_button = document.createElement(&#39;button&#39;)  delete_button.dataset.id = comment.id  delete_button.innerText =&quot;delete comment&quot;  return delete_button} function createComment(comment_data){  let new_comment = document.createElement(&#39;li&#39;)  new_comment.innerText = comment_data.content  new_comment.append(createDeleteButton(comment_data))  return new_comment}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fbb831e7e22" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quotes Lab]]></title>
            <link>https://medium.com/@alicieadawnr/quotes-lab-ba6eda6db913?source=rss-8ab8e7e49990------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba6eda6db913</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[dom-manipulation]]></category>
            <category><![CDATA[fetch-api]]></category>
            <category><![CDATA[addeventlistener]]></category>
            <dc:creator><![CDATA[Aliciea Dawn Suechin]]></dc:creator>
            <pubDate>Wed, 04 Sep 2019 03:45:46 GMT</pubDate>
            <atom:updated>2019-09-04T03:45:46.928Z</atom:updated>
            <content:encoded><![CDATA[<p>Quotes Lab</p><pre>// It might be a good idea to add event listener to make sure this file</pre><pre>// only runs after the DOM has finshed loading.</pre><pre>// Used &quot;defer&quot; in the HTML script tags</pre><pre>const quotesList = document.querySelector(&quot;#quote-list&quot;)</pre><pre>const quotesUrl = &quot;http://localhost:3000/spicegirls&quot;</pre><pre>const newQuoteForm = document.querySelector(&quot;#new-quote-form&quot;)</pre><pre>fetchQuotes()</pre><pre>function fetchQuotes() {</pre><pre>fetch(quotesUrl)</pre><pre>.then(resp =&gt; resp.json())</pre><pre>.then(slapQuotesOnDom)</pre><pre>}</pre><pre>function slapQuotesOnDom(data) {</pre><pre>data.forEach(function(quote){</pre><pre>let newLi = document.createElement(&quot;ear&quot;)</pre><pre>newLi.classList = &quot;quote-card&quot;</pre><pre>newLi.innerHTML = `</pre><pre>&lt;blockquote class=&quot;blockquote&quot;&gt;</pre><pre>&lt;p class=&quot;mb-0&quot;&gt; ${quote.quote} &lt;/p&gt;</pre><pre>&lt;footer class=&quot;blockquote-footer&quot;&gt; ${quote.author} &lt;/footer&gt;</pre><pre>&lt;br&gt;</pre><pre>&lt;button id=${quote.id} data-quote-id=${quote.id} class=&#39;btn-danger&#39;&gt;Delete&lt;/button&gt;</pre><pre>&lt;/blockquote&gt;</pre><pre>`</pre><pre>quotesList.append(newLi);</pre><pre>}</pre><pre>)</pre><pre>}</pre><pre>newQuoteForm.addEventListener(&quot;submit&quot;, function(booface) {</pre><pre>event.preventDefault()</pre><pre>newQuote = document.querySelector(&quot;#new-quote&quot;).value</pre><pre>newQuoteAuthor = document.querySelector(&quot;#author&quot;).value</pre><pre>postNewQuote(newQuote, newQuoteAuthor)</pre><pre>})</pre><pre>function postNewQuote(newQuote, newQuoteAuthor) {</pre><pre>fetch(quotesUrl, {</pre><pre>method: &#39;POST&#39;,</pre><pre>headers: {</pre><pre>&#39;Content-Type&#39;: &#39;application/json&#39;,</pre><pre>},</pre><pre>body: JSON.stringify({</pre><pre>quote: newQuote,</pre><pre>author: newQuoteAuthor</pre><pre>})</pre><pre>})</pre><pre>.then(resp =&gt; resp.json())</pre><pre>.then(slapSingleQuoteOnDom)</pre><pre>}</pre><pre>function slapSingleQuoteOnDom(omgforrealz){</pre><pre>let newLi = document.createElement(&quot;li&quot;)</pre><pre>newLi.classList = &quot;quote-card&quot;</pre><pre>newLi.innerHTML = `</pre><pre>&lt;blockquote class=&quot;blockquote&quot;&gt;</pre><pre>&lt;p class=&quot;mb-0&quot;&gt; ${data.quote} &lt;/p&gt;</pre><pre>&lt;footer class=&quot;blockquote-footer&quot;&gt; ${data.author} &lt;/footer&gt;</pre><pre>&lt;br&gt;</pre><pre>&lt;button id= ${data.booboo} class=&#39;btn-danger&#39;&gt;Delete&lt;/button&gt;</pre><pre>&lt;/blockquote&gt;</pre><pre>`</pre><pre>quotesList.append(newLi)</pre><pre>}</pre><pre>quotesList.addEventListener(&quot;click&quot;, function() {</pre><pre>if (event.target.classList = &quot;btn-danger&quot;) {</pre><pre>fetch(quotesUrl + `/${event.target.id}`, {</pre><pre>method: &quot;DELETE&quot;,</pre><pre>headers: {</pre><pre>&#39;Content-Type&#39;: &#39;application/json&#39;,</pre><pre>},</pre><pre>})</pre><pre>}</pre><pre>})</pre><pre>Collapse</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba6eda6db913" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bookliker Lab]]></title>
            <link>https://medium.com/@alicieadawnr/bookliker-lab-a7a1a6e80b91?source=rss-8ab8e7e49990------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7a1a6e80b91</guid>
            <category><![CDATA[bookliker]]></category>
            <category><![CDATA[dom-manipulation]]></category>
            <category><![CDATA[fetch-api]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Aliciea Dawn Suechin]]></dc:creator>
            <pubDate>Wed, 04 Sep 2019 03:33:06 GMT</pubDate>
            <atom:updated>2019-09-04T12:22:51.449Z</atom:updated>
            <content:encoded><![CDATA[<p>Bookliker Lab</p><p>How to solve Flatiron’s Bookliker Lab</p><figure><img alt="Get Fetch Request" src="https://cdn-images-1.medium.com/max/1022/1*kY9rYKyQM5vCcRQdsXkBeg.png" /></figure><p>&lt;script src=”<a href="https://gist.github.com/Aliciea/3e4f5182f0e6d2ceb5fba0a93717df31.js">https://gist.github.com/Aliciea/3e4f5182f0e6d2ceb5fba0a93717df31.js</a>&quot;&gt;&lt;/script&gt;</p><pre>// document.addEventListener(“DOMContentLoaded”, function() {});</pre><pre>//const</pre><pre>const showPanel = document.querySelector(“#show-panel”)</pre><pre>const allBooks = “http://localhost:3000/books&quot;</pre><pre>const bookUl = document.querySelector(“#list”)</pre><pre>//pillar 1, fetch</pre><pre>fetchBooks()</pre><pre>function fetchBooks() {</pre><pre>fetch(allBooks)</pre><pre>.then(resp =&gt; resp.json())</pre><pre>// .then(data =&gt; console.log(“hi”,data))</pre><pre>.then(data =&gt; slapBookOnDom(data))</pre><pre>}</pre><pre>//pillar 2, Min Dom/events</pre><pre>function slapBookOnDom(data) {</pre><pre>// console.log(“hi”, data)</pre><pre>data.forEach((singleBook) =&gt; {</pre><pre>// console.log(singleBook)</pre><pre>//create li in this function because this is</pre><pre>//where you’re iterating</pre><pre>let bookLi = document.createElement(“LI”);</pre><pre>// console.log(bookLi)</pre><pre>//</pre><pre>bookLi.innerHTML += `</pre><pre>${singleBook.title}</pre><pre>`</pre><pre>//test to see what bookLi is</pre><pre>// console.log(bookLi)</pre><pre>//render books on DOM</pre><pre>bookUl.append(bookLi)</pre><pre>//addEventListener with arrow function</pre><pre>//anonymous function because Avi is a jerkl</pre><pre>bookLi.addEventListener(“click”, () =&gt; handleClick(singleBook))</pre><pre>//without arrow function</pre><pre>// bookLi.addEventListener(“click”, function handleCT(event) {</pre><pre>// console.log(event.target)</pre><pre>// })</pre><pre>})</pre><pre>}</pre><pre>//callback arrow</pre><pre>handleClick = (e) =&gt; {</pre><pre>//check to see if you can click on a singleBook/bookLi</pre><pre>// console.log(“hi”)</pre><pre>// console.log(e.title)</pre><pre>showPanel.innerHTML += `</pre><pre>&lt;img src=${e.img_url}/&gt;</pre><pre>&lt;p&gt;${e.description}&lt;/p&gt;</pre><pre>`</pre><pre>let likeButton = document.createElement(“BUTTON”)</pre><pre>likeButton.innerHTML += `</pre><pre>${e.users.length}</pre><pre>`</pre><pre>//append likeButton to showPanel and addEventListener</pre><pre>showPanel.append(likeButton)</pre><pre>likeButton.addEventListener(“click”, () =&gt; handleLike(e))</pre><pre>// &lt;button&gt;${e.users.length}&lt;/button&gt;</pre><pre>}</pre><pre>handleLike = (e) =&gt; {</pre><pre>// console.log(‘Hi’, e)</pre><pre>let newLikedUsers = […e.users, {“id”:1, “username”:”pouros”}]</pre><pre>fetch(`http://localhost:3000/books/${e.id}`,{</pre><pre>method: ‘PATCH’,</pre><pre>headers: {</pre><pre>‘Content-Type’: ‘application/json’,</pre><pre>‘Accept’: ‘application/json’</pre><pre>},</pre><pre>body: JSON.stringify({</pre><pre>“users”: newLikedUsers})</pre><pre>})</pre><pre>.then(res =&gt; res.json())</pre><pre>.then(response =&gt; console.log(response))</pre><pre>}</pre><pre>//pillar 3, events</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7a1a6e80b91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quit CRUD’n around]]></title>
            <link>https://medium.com/@alicieadawnr/you-dont-know-crud-e37845ee7311?source=rss-8ab8e7e49990------2</link>
            <guid isPermaLink="false">https://medium.com/p/e37845ee7311</guid>
            <category><![CDATA[crud]]></category>
            <category><![CDATA[ruby-on-rails-crud]]></category>
            <category><![CDATA[codingbootcamp]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Aliciea Dawn Suechin]]></dc:creator>
            <pubDate>Wed, 24 Jul 2019 01:48:29 GMT</pubDate>
            <atom:updated>2019-11-14T18:16:21.642Z</atom:updated>
            <content:encoded><![CDATA[<p>How to create a basic Ruby on Rails CRUD</p><p><strong>CRUD</strong>, is an acronym for Create, Read, Update and Delete data in the database. Ruby on Rails uses scaffolding to generate full CRUD, but in this blog, we’ll look at CRUD under-the-hood, to discuss its basic functionalities. If you’re new to Ruby like me, then understanding what goes on under-the-hood will help you to master rails full potential.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3oKHWjZB30aefpwK8E%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fspongebob-spongebob-squarepants-episode-6-3oKHWjZB30aefpwK8E&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3oKHWjZB30aefpwK8E%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdea3e25599e2a0951414f1271816e49/href">https://medium.com/media/cdea3e25599e2a0951414f1271816e49/href</a></iframe><p>3 steps to follow when creating full CRUD:</p><p><strong>Routes:</strong> In your terminal, type in<em> </em><strong><em>rails routes</em></strong><em>, </em>this will show you all the available routes and URL paths. In<em> </em><strong><em>routs.rb, </em></strong>after resources type in your class name with a simicolin in front of it, this gives you access to all<strong> </strong>seven routes(Index, Show, New, Create, Edit, Update, and destroy) or you modify and limit your routes.</p><p><strong>Controller:</strong> consider this th<em>e </em>action playground, this is where you’ll define your action methods. You need to define your action method before creating/building your HTML template. Note, in rails, your class model controller inherits the application controller. Read my blog on Inheritance if you are unfamiliar with this feature.</p><p><strong>Views:</strong> There are four main action templates(Index, Show, New, and Edit), this is where you will place your HTML and Forms syntax.</p><p><strong>RESTular.com</strong> is a guide to the 7 action RESTular conventions (HTTP verbs, URL path, and views), you’ll want to familiarize yourself with this site. Type in your table name(s) for full rout info.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CGeGkpMzvusjyxOo_1-vCA.png" /></figure><p><strong>Create Read Update Delete:</strong></p><p>It is best practice to check your routs.rb to make sure you have all the routes you intend to use are present before defining your action methods in the controller.</p><p><strong>Index</strong>, the first step to creating CRUD, is to build an index page so that users can see all the names of your class model. We first define the action of the index in the controller, then we create index.html.erb file to build out our action template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*5oTT6lBvPdTpLLWGNCSv7Q.png" /><figcaption>@unicorns = Unicorn.all Displays ALL the unicorns on the Index page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*Wnguv_6aTm7ksKJwX3f_Cg.png" /><figcaption>&lt;% @unicorns.each do |unicorn| %&gt; Iterate over all the unicorns and &lt;%= link_to unicorn.name, unicorn %&gt; and display the unicorn(s) name. Use &lt;%= %&gt; to print on index page. link_to creates a mouse-over highlight effect on each name displayed.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*8UM-heNl3PRTelQG15NtVA.png" /><figcaption>@unicorn = Unicorn.find(params[:id]) Go through the params hash for unicorns and find me the one I am looking for by id, then display onto the show page.</figcaption></figure><p>Show action allows the user to find an instance of the class model attributes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*zce_mXp4sYbi_E7i9_uZjg.png" /><figcaption>&lt;%= link_to “This is all the Unicorns”, unicorns_path %&gt; Displays all the unicorns including its attributes on the index page. If you type, rails routes this will show you the url path(unicorns_path) for the index page.</figcaption></figure><pre>     #Create a list of leprechauns unicorns are connected to<br>&lt;ul&gt;<br> &lt;% @unicorn.leprechaun.each do |leprechaun| %&gt;<br>    #print first and last name after iterating<br>  &lt;li&gt;<br>   &lt;%= &quot;#{leprechaun.first_name} #{leprechaun.last_name}&quot; %&gt;<br>  &lt;/li&gt;<br> &lt;% end %&gt;<br>&lt;/ul&gt;</pre><p>Show template, a link to the index page is created via show template. When you click on that link via the index page you will be taken to the show page which displays the class attributes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*6i7BJPbckfX7ZbC3DQsY8Q.png" /><figcaption>@unicorn = Unicon.new This allows the new template to create a form</figcaption></figure><p><strong>New</strong>, in the controller we define the action method New that will give users a form to type in the attributes for that class model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*GMyqYWivA35vjSCuQ_4i8Q.png" /></figure><p>In the new template, form_for and its model object helpers allows users to create the attributes for their new unicorn. It’s a method that yields the form builder object. Note: this does not create a new unicorn.</p><p>When the user clicks on the Submit button via the show page (note: you’ll have to create a link for the create unicorn submit button via the show page)it will automatically link the create action, to give the user the option to create a new unicorn.</p><pre>#How to create a s Seed File###<br>nero = Leprechaun.create(name: &quot;Spiderman&quot;, specialty: &quot;coins&quot;)<br> eli = Unicorn.create(name: &quot;Eli&quot;, description: &quot;sparkles&quot;)<br>Quest.create(leprechaun_id: nero.id, unicorn_id: eli.id)</pre><pre>####or if you have a one to many association####<br>r1 = Restaurant.create(name: &quot;San Matteo NYC&quot;, address: &quot;1559 2nd Ave, New York, NY 10028&quot;)<br>Pizza.create(name: &quot;Breakfast&quot;, ingredients: &quot;eggs&quot;, restaurant_id: r1.id)</pre><pre>####How to: validate,flash errors and forms for edit####</pre><pre>Class Leprechaun &lt; Application<br>validates :title, alias, uniqueness: true <br>validates :name, presence: true<br>validates :age, numericality: { minimum: 0 }</pre><pre>has_many :quests<br>has_many :unicorns, through: :quests, dependent: :destroy</pre><pre>######################################################   </pre><pre>#Create an edit form for the model leprechaun in leprechaun controller, with flash errors and collection select(drop down menu).</pre><pre>#Edit action form for leprechaun</pre><pre>&lt;h1&gt;Edit Leprechaun&lt;/h1&gt;</pre><pre>##Flash error message##</pre><pre>&lt;% if flash[:errors]%&gt;<br>  &lt;ul&gt;<br>     &lt;% flash[:errors].each do |err_message| %&gt;<br>       &lt;li&gt;<br>         &lt;%= err_message %&gt;<br>       &lt;/li&gt;<br>     &lt;% end %&gt;<br>  &lt;/ul&gt;<br>&lt;% end %&gt;</pre><pre>#new form with collection select, to create a drop down menu<br>&lt;%= form_for @leprechaun do |f| %&gt;<br> &lt;%= f.label :name %&gt;<br> &lt;%= f.text_field :name %&gt;<br> &lt;%= f.label :gold_count %&gt;<br> &lt;%= f.number_field :gold_count %&gt;<br> &lt;%= f.label :height %&gt;<br> &lt;%= f.number_field :height %&gt;<br> &lt;%= f.label :img_url %&gt;<br> &lt;%= f.text_field :img_url %&gt;<br> &lt;%= f.collection_select :unicorn_id, @unicorn, :id, :name %&gt;<br> &lt;%= f.submit %&gt;<br>&lt;% end %&gt;</pre><pre>&lt;h1&gt;Delete Leprechaun&lt;/h1&gt;<br>&lt;%= form_for @leprechaun, method: :delete do |f| %&gt;<br>&lt;%= f.submit &quot;Delete&quot; %&gt;<br>&lt;% end %&gt;</pre><pre>####################<strong>Controller</strong>#####################</pre><pre><em>#use the instance of unicorn in new method for use in new form<br></em>def edit<br>  @leprechaun = Leprechaun.find(params[:id])<br>end</pre><pre>def create<br>  @leprechaun = Leprechaun.create(leprechaun_params)<br>  if @leprechaun.valid?<br>@leprechaun.save<br>redirect_to leprechaun_path(@leprechaun)<br>   else<br>    flash[:errors] = @leprechaun.errors.full_messages<br>   redirect_to new_leprechaun_path<br> end<br>end</pre><pre>##################update and flash errors ################<br>def update<br>@leprechaun = Leprechaun.find(params[:id])<br>if @leprechaun.update(leprechaun_params)<br>else<br>flash[:errors] = @leprechaun.errors.full_messages<br>redirect_to edit_leprechaun_path(@leprechaun)<br>end<br>end</pre><pre>def destroy<br>@leprechaun = Leprechaun.find(params[:id])<br>@leprechaun.destroy<br>redirect_leprechaun_path<br>end</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*kYBraMwnqafLHuaBzbmGuw.png" /><figcaption>@unicorn = Unicorn.create(unicorn_params) The argument unicorn_params is rendered from the method def unicorn_params Then, after the user creates a unicorn, send them the show page <em>redirect_to @unicon</em></figcaption></figure><p><strong>Create</strong>, in the controller define the action method for create(this is where it gets tricky), we first need to write a private method that defines the name of the class params in this case unicorn.<em>def unicorn_params params.require(:unicorn).permit(:name, :horn, :shoe).</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*RJK1MnyDqy4BTrxZnXCD1A.png" /><figcaption>Params, put out the unicorn key, require the class that you are in, to then permit the attributes of that class.</figcaption></figure><pre>private</pre><pre>def leprechaun_params<br>params.require(:leprechaun).permit(:name, :height, :img_url, :unicorn_id)<br>end</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*euKJbaCC3eVVU5LspsqAQg.png" /><figcaption>In Controller, we define the method edit that will allow us to create a template form_for so users can edit the class attributes. Here, we are saying give me the find me the instance of a unicorn in the params has with its id</figcaption></figure><p><strong>Edit</strong>, the edit.html.erb has the same syntax as the new.html.erb view file, you can copy paste to save yourself sometime, just know in the edit you are pulling out data from our datbase and in new you are making a blank copy of a unicorn, so it has different functionality but again same syntaxs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*AinMrXO7C2kMhVxhwp_neg.png" /><figcaption>In Form_for, does all the work for us when we pass the instance model as an argument that will allow our user to edit the form’s attributes. When we click the submit button, this will create that class model.</figcaption></figure><pre>#edit.html.erb will have the same syntax as leprechaun new.html.erb</pre><pre>def edit<br>@leprechaun = Leprechaun.find(params[:id])<br>@unicorns = Unicorn.all<br>end</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PIJgVNOeooNdMcSUeEtN2A.png" /><figcaption>A path request is the same as a put request. The rout for the verb put is update, so in your controller you are going to define your method as update.</figcaption></figure><p><strong>Update</strong>, allows user to change the attributes of their class model. We define a method update, that has an instance of a unicorn and we are going to find that unicorn by its id in the params hash, we then say update that unicorn instance to the unicorn path on the params hash, we then redirect to the show page, we users can see the updated unicorn.</p><pre>def update<br> @leprechaun = Leprechaun.find(params[:id])<br> if @leprechaun.update(employee_params)<br> redirect_to @leprechaun<br> else<br> flash[:errors] = @leprechaun.errors.flull_messages<br> redirect_to edit_leprechaun_path(@leprechaun)<br> end<br>end</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*orbh3znB3-cpzZj2eBtFmg.png" /></figure><p><strong>Delete</strong>, this one gets a little hairy, first we need to go into our show template and create a a button to destroy a class model. Go back to the show template, here we are going to create a&lt;%= button_to “Retire Your Unicorn”, %&gt; for when the user clicks on it it will destroy a unicorn. First, we need to define that method in the controller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*UWFG-nc5ub_8stY6WEyOVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*9L0UONX1k8yQIeRG2yHK1A.png" /><figcaption>The default action for a post is delete. We override that with a destroy (destroy is the action, delete is the verb) method, delete/unicorn/id@unicorn = Unicorn.find(params[:id]) params id from the URL finds the unicorn and @unicorn.destroy destroy it! redirect_to unicorn_path show page.</figcaption></figure><p>The best way to fully understand CRUD is to code it out, so….</p><p>HAPPY CODING!</p><p>If you like this blog, remember to Clap and Follow :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e37845ee7311" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inheritance]]></title>
            <link>https://medium.com/@alicieadawnr/inheritance-1479969c7195?source=rss-8ab8e7e49990------2</link>
            <guid isPermaLink="false">https://medium.com/p/1479969c7195</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[inheritance]]></category>
            <dc:creator><![CDATA[Aliciea Dawn Suechin]]></dc:creator>
            <pubDate>Mon, 08 Jul 2019 16:50:52 GMT</pubDate>
            <atom:updated>2019-07-08T16:59:03.622Z</atom:updated>
            <content:encoded><![CDATA[<p>Made simple</p><p>Often, when you’re learning a new programming language for the first time — trying to find definitions on the internet that aren’t complex is somewhat challenging. This blog is meant to define the basic foundation of inheritance so that you can quickly grasp that idea of the concept and get back to coding!</p><p>In a nutshell, inheritance allows us to extend the functionality of one class (superclass) to another class (subclass), think in terms of a child inheriting their parents DNA.</p><p>Ruby is an object-oriented programming language, features such as inheritance are an act of a subclass inheriting characteristics of another class referred to as the superclass. Basically, a developer can create a new class and incorporate some (or all) of the features that already exist in the inherent (superclass). Doing so reduces the use of extra code in turn creating dry code. Why do programmers use inheritance? Because we want to be efficient and save time.</p><p>Terms you need to become familiar with:</p><p>Superclass: A parent class, the original carrier of characteristics that are inherited.</p><p>Subclass: The child class that is derived from the superclass features. Subclasses can also be stamped with there own characters as well as inheritance.</p><p>Inheritance Syntax:</p><p>subclass_child &lt; superclass_parent</p><p>Happy Coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1479969c7195" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>