<?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: dandanthemanman</title>
    <description>The latest articles on DEV Community by dandanthemanman (@dandanthemanman).</description>
    <link>https://dev.to/dandanthemanman</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F862971%2F7df6a98d-fd91-48a2-a1ca-7e7dea65af22.png</url>
      <title>DEV Community: dandanthemanman</title>
      <link>https://dev.to/dandanthemanman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dandanthemanman"/>
    <language>en</language>
    <item>
      <title>How to render data from multiple models using a serializer</title>
      <dc:creator>dandanthemanman</dc:creator>
      <pubDate>Tue, 05 Jul 2022 12:47:13 +0000</pubDate>
      <link>https://dev.to/dandanthemanman/how-to-render-data-from-multiple-models-using-a-serializer-32o6</link>
      <guid>https://dev.to/dandanthemanman/how-to-render-data-from-multiple-models-using-a-serializer-32o6</guid>
      <description>&lt;p&gt;If you've already learned how to relate models in rails using macro associations like: &lt;br&gt;
&lt;code&gt;belong_to&lt;/code&gt;&lt;br&gt;
&lt;code&gt;has_many&lt;/code&gt; &lt;br&gt;
 or &lt;br&gt;
&lt;code&gt;has_many, through:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You may be wondering how these relationships manifest themselves when you actually pull data from your models. The answer is: they don't. That is, unless you use a serializer with your model. &lt;/p&gt;

&lt;p&gt;A serializer is a separate file that kind of acts like a filter to its model. It determines what attributes from the model's records will be rendered or not rendered. &lt;/p&gt;

&lt;p&gt;So, for example, we could have a model whose records have 100 attributes, but in a specific fetch request, we only want to render 3 of them. We would program that using a serializer.&lt;/p&gt;

&lt;p&gt;To create a serializer file, use the command: &lt;br&gt;
&lt;code&gt;$ rails g serializer Model_name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;By default, the serializer will be linked to the model that shares its name. &lt;/p&gt;

&lt;p&gt;Once the serializer is created, enter the file Model_name_serializer.rb and add the macro associations you want to use when rendering data.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;class ModelNameSerializer&lt;br&gt;
has_many :other_models&lt;br&gt;
end&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, when you pull a record from "Model_Name," it will not only render that specific record, but also the nested records of "Other_model" that belong to it. &lt;/p&gt;

&lt;p&gt;This can be useful if you want to use data from various related models in a single fetch statement. &lt;/p&gt;

</description>
      <category>rails</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to add Bootstrap to your React app</title>
      <dc:creator>dandanthemanman</dc:creator>
      <pubDate>Sun, 12 Jun 2022 16:32:57 +0000</pubDate>
      <link>https://dev.to/dandanthemanman/how-to-add-bootstrap-to-your-react-app-24kk</link>
      <guid>https://dev.to/dandanthemanman/how-to-add-bootstrap-to-your-react-app-24kk</guid>
      <description>&lt;p&gt;When I started building projects and wanted to make them look good, I soon learned Bootstrap was an efficient way to style them. It's also pretty intuitive (which is a godsend). &lt;/p&gt;

&lt;p&gt;Unfortunately, I got stuck at the first step: installing Bootstrap.&lt;/p&gt;

&lt;p&gt;Hopefully this will save you from getting stuck at the installation too. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;run &lt;code&gt;$npm install bootstrap react-bootstrap&lt;/code&gt; in your React app's directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, it's time to ask yourself specifically what you want to style: buttons, the navbar, do you want to add cards? Browse through what bootstrap has to offer here: &lt;a href="https://react-bootstrap.github.io/components/alerts/"&gt;https://react-bootstrap.github.io/components/alerts/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once you've perused through all the components Bootstrap has, and some have caught your eye, navigate to the file where you want to use them. Here, you'll import the specific component at the top of the file by writing: &lt;code&gt;import { Component } from "react-bootstrap"&lt;/code&gt; (include the name of the component you want)&lt;br&gt;
Underneath that, include: &lt;code&gt;import "bootstrap/dist/css/bootstrap.min.css";&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now you're free to include that component in your file. &lt;br&gt;
If you want to add different components, simply add them to the curly braces at the import at the top of the file: &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;import { Component1, Component2 } from "react-bootstrap"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Congrats! You've installed Bootstrap and included components in your app. Now, you can focus on styling the components to your preference.&lt;/p&gt;

&lt;p&gt;... how do you do that?  &lt;/p&gt;

&lt;p&gt;The styling in Bootstrap is done primarily through the component's attributes. For example: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Component variant="primary"&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;... will give you the pre-styled "primary" version of this component.&lt;/p&gt;

&lt;p&gt;You can find these attributes and examples of what styles they offer in the "components" section of the Bootstrap docs we looked at before: &lt;br&gt;
&lt;a href="https://react-bootstrap.github.io/components/alerts/"&gt;https://react-bootstrap.github.io/components/alerts/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope this helped. For a great tutorial on how to use basic Bootstrap components: &lt;a href="https://www.youtube.com/watch?v=8pKjULHzs0s"&gt;https://www.youtube.com/watch?v=8pKjULHzs0s&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Write an API patch route in Sinatra</title>
      <dc:creator>dandanthemanman</dc:creator>
      <pubDate>Fri, 03 Jun 2022 20:49:28 +0000</pubDate>
      <link>https://dev.to/dandanthemanman/write-an-api-patch-route-in-sinatra-1gd4</link>
      <guid>https://dev.to/dandanthemanman/write-an-api-patch-route-in-sinatra-1gd4</guid>
      <description>&lt;p&gt;While learning to write Sinatra API routes, the PATCH route was the most confusing for me. If you're in the same boat, the following 5 steps should help. &lt;/p&gt;

&lt;p&gt;Before we start, you need to make a ruby file called "application_controller.rb" in app/controllers.&lt;/p&gt;

&lt;p&gt;First: In the new file declare the class ApplicationController.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ApplicationController &amp;lt; Sinatra::Base

end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Second: Write the method "patch" &lt;br&gt;
Add the model where the instance you're changing lives.&lt;br&gt;
Add "/:id" to the end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ApplicationController &amp;lt; Sinatra::Base

patch "/table/:id" do

end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Third: Use find() and the params id to locate the instance in the model, and declare a variable with it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ApplicationController &amp;lt; Sinatra::Base

patch "/desiredtable/:id" do
desiredRecord = DesiredModel.find(params[:id])
end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fourth: Now, we'll update this variable's attribute. &lt;br&gt;
Update it with the value we pull from the params.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ApplicationController &amp;lt; Sinatra::Base

patch "/desiredtable/:id" do
desiredRecord = DesiredModel.find(params[:id])
desiredRecord.update(attribute: params[:attribute])
end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fifth: (last but certainly not least) Convert the variable to JSON.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ApplicationController &amp;lt; Sinatra::Base

patch "/desiredtable/:id" do
desiredRecord = DesiredModel.find(params[:id])
desiredRecord.update(attribute: params[:attribute])
desiredRecord.to_json
end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Done!&lt;/p&gt;

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