<?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: EvanRPavone</title>
    <description>The latest articles on DEV Community by EvanRPavone (@evanrpavone).</description>
    <link>https://dev.to/evanrpavone</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%2F570911%2F67c3faa6-7f32-45d1-b995-383c70bcddb2.png</url>
      <title>DEV Community: EvanRPavone</title>
      <link>https://dev.to/evanrpavone</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/evanrpavone"/>
    <language>en</language>
    <item>
      <title>MongoDB - My first introduction</title>
      <dc:creator>EvanRPavone</dc:creator>
      <pubDate>Fri, 23 Jul 2021 15:42:36 +0000</pubDate>
      <link>https://dev.to/evanrpavone/mongodb-my-first-introduction-22k1</link>
      <guid>https://dev.to/evanrpavone/mongodb-my-first-introduction-22k1</guid>
      <description>&lt;h5&gt;
  
  
  Introduction
&lt;/h5&gt;

&lt;p&gt;This week I had a few things I had to focus on so I don’t really have much to talk about. I did however start a new project with React by using the MERN framework which uses ReactJS, NodeJS, ExpressJS and MongoDB. Today I will be trying to tell you about MongoDB.&lt;/p&gt;

&lt;h5&gt;
  
  
  What is MongoDB?
&lt;/h5&gt;

&lt;p&gt;MongoDB is a NoSQL database that contains a data model, which allows you to store a lot of data and represent relationships. The basic units of data are the key value pairs that are contained in the JSON documents which contain the schema instead of using tables and rows. I come from using Rails to create my backend data, so this is all new to me. This database system also has a lot of characteristics like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Support for ad hoc queries ( loosely typed query/on the fly query)&lt;/li&gt;
&lt;li&gt;Replication&lt;/li&gt;
&lt;li&gt;Indexing&lt;/li&gt;
&lt;li&gt;Load Balancing&lt;/li&gt;
&lt;li&gt;Data Duplication&lt;/li&gt;
&lt;li&gt;Schema-less database&lt;/li&gt;
&lt;li&gt;Procedures instead of JavaScript&lt;/li&gt;
&lt;li&gt;Easy to maintain/administrate&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Common Use
&lt;/h5&gt;

&lt;p&gt;MongoDB is used to store data, manage the data, retrieve data, create web applications and store a lot of data. So basically what you think a database would do for a web application. &lt;/p&gt;

&lt;h5&gt;
  
  
  Next Week:
&lt;/h5&gt;

&lt;p&gt;As I start my new React Project using this type of framework I will be learning a lot of new things that I would like to share with you so come back next week to see what I have learned using a MERN stack and MongoDB. &lt;/p&gt;

</description>
      <category>database</category>
      <category>learning</category>
    </item>
    <item>
      <title>Learning Python - Week 6</title>
      <dc:creator>EvanRPavone</dc:creator>
      <pubDate>Fri, 16 Jul 2021 13:32:16 +0000</pubDate>
      <link>https://dev.to/evanrpavone/learning-python-week-6-3mb0</link>
      <guid>https://dev.to/evanrpavone/learning-python-week-6-3mb0</guid>
      <description>&lt;p&gt;This was my final week of Python! To finish it off I learned about File IO and the OS module which help with creating files and running files. &lt;/p&gt;

&lt;h5&gt;
  
  
  File IO
&lt;/h5&gt;

&lt;p&gt;You can use python to open files and there are a few ways to do this using File IO. You can use this to read from a file, add to an existing file or overwrite a file. One is just using the open method which would need to be followed up by the close method and the Second being using with which does all of that for you:&lt;br&gt;
First option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myfile = open('/Users/&amp;lt;user&amp;gt;/Documents/Coding/Python/LearningPython/fileIO-example/sample.txt') # cant have this file be opened more than once

content = myfile.read() # reads the contents of sample.txt from beginning to end
print(content)

myfile.seek(0) # will put the cursor at the beginning of the file. resets the cursor

print("---------------")
data = myfile.read() # will not read if printed. The read function takes the cursor from the beginning all the way to the end. so when the content variable is printed the cursor is at the end and will not go back.
print(data)

myfile.seek(0) # will put the cursor at the beginning of the file. resets the cursor

print("---------------")

content_list = myfile.readlines() # to read each line there is a readlines method. each line in the file will be saved in its own element in the list

myfile.close() # will close the file

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

&lt;/div&gt;



&lt;p&gt;Second Option: ( I prefer this way )&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;with open('/Users/evanpavone/Documents/Coding/Python/LearningPython/fileIO-example/sample.txt', mode='a') as my_file:
    """
    This open syntax already opens and closes the file
    If I change the filename it will make a new file in that location if I use the write mode
    MODES:
    a = append - adds to the file
    w = write - overwrites the file. The data will be replaced
    r = read - cannot write to it. Read only mode
    r+ = read and write
    w+ = override the file completely and have the ability to read it
    """
    my_file.write("\nThis is my sentence") # appended to the end of the file

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

&lt;/div&gt;



&lt;h5&gt;
  
  
  File IO Exception Handling
&lt;/h5&gt;

&lt;p&gt;Last week I talked about exception handling using try and except. Well, this week I found out that you can specify what to do for each type of error. For example, if I had a TypeError, I could specify what would happen if a type error occurred if I ran my code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_file = None

try:
    my_file = open('/Users/evanpavone/Documents/Coding/Python/LearningPython/fileIO-example/sample.txt', mode="r")
    print(my_file.read())
except IOError:
    """
    There are different types of exception errors. TypeError, FileNotFoundError etc...
    You can capture specific errors
    """
    print("Issue with working with the file...")
except:
    # general catch all error
    print("Error occurred, logging to the system")
finally:
    if my_file != None:
        my_file.close()
    print("This will always run regardless of whether we have an exception or not")

print("This line was run...")

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

&lt;/div&gt;



&lt;h5&gt;
  
  
  OS Module
&lt;/h5&gt;

&lt;p&gt;From what I learned about OS Module is that it helps with file paths and making sure that the folder contains files, etc.Os Module all starts with importing os at the top of the file &lt;code&gt;import os&lt;/code&gt;. Importing OS allows you to use a bunch of methods like getcwd, mkdir, makedirs, rmdir, etc. Here are a bunch of methods within the os module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;os.cwd() # gets the current working directory
os.chdir(“/Users/&amp;lt;user&amp;gt;/Desktop”) # changes directory location - in this case changes directory to desktop
os.listdir() # lists the contents of the directory
os.mkdir() # creates a folder in the current directory
os.makedirs() # creates multiple directories - good for having nested folders
os.rmdir() # deletes specific directory
os.remove() # removes files from the directory
os.walk() # “walks you through a directory and tells you each file and folder - I will show example with a for loop
os.environ.get("HOME") + "/" + "myfile.txt" # -&amp;gt;  /Users/&amp;lt;user&amp;gt;/myfile.txt
os.path.join(os.environ.get("HOME"), "myfile.txt" # -&amp;gt; /Users/&amp;lt;user&amp;gt;/myfile.txt
os.path.basename("/bin/tools/myfile.txt") # myfile.txt - used to get basename... thats the file at the directory location given
os.path.dirname("/bin/tools/myfile.txt") #  /bin/tools - get the directory name only, not the file
os.path.split("/bin/tools/myfile.txt") # ('/bin/tools', 'myfile.txt') - will give directory name and basename in a tuple
os.path.exists("/bin/tools/myfile.txt") # False - used to check if the path exists on the computer
os.path.isfile("/bin/tools/myfile.txt") # used to check if file exists in the specified path
os.path.isdir("/bin/tools/myfile.txt") # check if directory exists in the specified path
os.path.splitext("/bin/tools/myfile.txt") # ('/bin/tools/myfile', '.txt') - get file with path and file extension in a tuple
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example of using the walk method in a for loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os

for dirpath, dirnames, filenames in os.walk("/Users/&amp;lt;user&amp;gt;/Documents/Coding/Python/LearningPython/myfolder"):
    # unpacking
    print(dirpath)
    print(dirnames)
    print(filenames)
    print(" ------------ ")

"""
/Users/&amp;lt;user&amp;gt;/Documents/Coding/Python/LearningPython/myfolder - dirpath
['stuff'] - dirnames
['sample.txt'] - filenames
 ------------ 
/Users/&amp;lt;user&amp;gt;/Documents/Coding/Python/LearningPython/myfolder/stuff - dirpath
['data'] - dirnames
['sample.txt'] - filenames
 ------------ 
/Users/&amp;lt;user&amp;gt;/Documents/Coding/Python/LearningPython/myfolder/stuff/data - dirpath
[] - dirnames - means no directory
['peacock.jpeg'] - filenames
 ------------ 
"""

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

&lt;/div&gt;



&lt;h5&gt;
  
  
  What I am thinking
&lt;/h5&gt;

&lt;p&gt;I am already starting to think of possibilities using these. I am curious to see if I could make a script that would install a selected language to a pc. Like, if I wanted to install Rails to a pc I could run a file that would ask me what language I want to install and I would select Rails and it would go through the process of installing it. I’m just rambling right now but I’m very curious.&lt;/p&gt;

&lt;h5&gt;
  
  
  What now
&lt;/h5&gt;

&lt;p&gt;Since this was my last week of learning python I am going to be get a better understanding of it and hopefully take the certification exam in the next few weeks. I had a lot of fun with python and I think it is up there with my favorite languages.&lt;/p&gt;

</description>
      <category>python</category>
      <category>learning</category>
    </item>
    <item>
      <title>Learning Python - Week 5</title>
      <dc:creator>EvanRPavone</dc:creator>
      <pubDate>Fri, 09 Jul 2021 14:12:42 +0000</pubDate>
      <link>https://dev.to/evanrpavone/learning-python-week-5-3j64</link>
      <guid>https://dev.to/evanrpavone/learning-python-week-5-3j64</guid>
      <description>&lt;p&gt;This is week 5 of learning python and this week I learned about python packages, script files and exception handling. I will be going over briefly about each section.&lt;/p&gt;

&lt;p&gt;Python packages are very useful. It keeps your code organized, especially if you have a lot of code to do. There are many packages online that you can download through your terminal. To install packages through your terminal you need to have python installed, that is a given, with python installed you can use the command pip3 which is a python package installer. The format you need to use to install packages is like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip3 install &amp;lt;package name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The top 10 packages for python are listed on this site, &lt;a href="https://www.kdnuggets.com/2021/03/top-10-python-libraries-2021.html"&gt;KDNuggets&lt;/a&gt;, it will tell you what each package is useful for. Each folder in the package has a file called &lt;strong&gt;init&lt;/strong&gt;.py, this is needed for each folder in a package. To use a package with its classes and methods, it is a lot like calling python code that is saved in another file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;From &amp;lt;package_name&amp;gt; import &amp;lt;module name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the package folder you will most likely have a main module file and folders. The main module file would have to have imported all the other files within each folder to be able to use them in your application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from &amp;lt;main_folder&amp;gt;.&amp;lt;sub_folder&amp;gt; import &amp;lt;module&amp;gt;,&amp;lt;another_module&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use * to get all the modules without listing them out.&lt;/p&gt;

&lt;p&gt;Now when it comes to making scripts in python, it is pretty easy. Create a python file and save it wherever you want on your computer. In the file put whatever you want, let’s say &lt;code&gt;print(“Hello There”)&lt;/code&gt;. In your terminal cd to where the file is located and in the terminal do&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 script_application.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should print out “Hello There”. Instead of having to type python3 in the terminal you can actually specify within the file that you’d like to use the Python interpreter to run the code. To do this add the following to the top of the script file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#! /usr/bin/env python3

print(“Hello There”)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might end up needing permission to run this file in the terminal now but that is an easy fix by running this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 755 &amp;lt;file name&amp;gt;.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can run your script with ease by typing &lt;code&gt;./&amp;lt;your script file&amp;gt;.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For exception handling, there are many ways to do this. I learned two ways using try/except and if else statement. Exception handling is definitely needed in order to be a good software engineer, so I’m told. If a user on your web application runs into an error, you do not want them to see a bunch of code exposing the inner workings of your site, instead you should just have them receive an error message on the site. Lets make a very simple method called sum that passes 2 numbers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def sum(num1, num2):
    print(num1 + num2)

number1 = input(“Enter a number:”)

sum(number1, 12)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above will give you an error and show you a lot of information you do not want your user to see. To fix this, I learned two ways, one is using the try except and the other is using an if else statement using isinstance method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Try/Except way
def sum(num1, num2):
    try: 
        print(num1+num2)
    except: 
        print(“There was an error!”)
number1 = input(“Enter a number:”)

sum(number1, 12)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code under the try method is what you want to happen. If the code ends up being an error like last time (it will for this as well), it will print “There was an error!” and will not show any of your code. The other way of doing this I still need to work on and understand but this is what I did following the instructor on my udemy course.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def sumAgain(num1, num2):
        if isinstance(num1, int) and isinstance(num2, int):
             print(num1+num2)
        else:
           print("data type was not a number for the parameters")

number1Again = input("Enter a number: ")
sumAgain(number1Again, 12)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I couldn’t really tell you what is going on here other than the fact that if the code ends up being an error it will print out “data type was not a number for the parameters”.&lt;/p&gt;

&lt;p&gt;Python is getting better and better and I am still enjoying it. I will most likely say that each post but I don’t have much longer to go in my course. I will see you next week!&lt;/p&gt;

</description>
      <category>python</category>
      <category>learning</category>
    </item>
    <item>
      <title>Learning Python - Week 4</title>
      <dc:creator>EvanRPavone</dc:creator>
      <pubDate>Fri, 02 Jul 2021 14:19:49 +0000</pubDate>
      <link>https://dev.to/evanrpavone/learning-python-week-4-42j9</link>
      <guid>https://dev.to/evanrpavone/learning-python-week-4-42j9</guid>
      <description>&lt;p&gt;Week 4 of learning Python has been very informative. I am starting to dive deeper into the Object Oriented side of things and learning about classes, class methods and how to reuse code from other files. This will also be a short post but I will try to get in as much information as possible.&lt;/p&gt;

&lt;p&gt;When I started to learn about the classes in Python I realized it is a lot like the other languages I have learned. What I mean by this is that they have initializers, in Python an initializer method is setup like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ClassName:
    def __init__(self, items):
        Self.the_items = items
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is important to have self because self is always pointing to the current object and that Python doesn’t use the @ syntax to refer to instance variables/attributes. If I were to have a subclass I would have to pass in the Parent class as an argument and have the methods of that subclass use self which would be referring to the Parent class self:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ClassName:
    def __init__(self, items):
        Self.the_items = items

class SubClassName(ClassName):
    def print_items(self):
        print(self.the_items)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's say you want to actually use these methods and put them in another file. To do so you would have to import these classes at the top of the new file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from foldername.filename import ClassName, SubClassName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then add your code. Here is an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from foldername.filename import ClassName, SubClassName

my_items = SubClassName([1,2,3,4,5])
# Then call the method to be able to run it
my_items.print_items()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will then print the items you have specified when calling the subclass, SubClassName, when you run your code.&lt;/p&gt;

&lt;p&gt;This is the main gist of what I have learned this week. I hope you got something out of this and see you next week!&lt;/p&gt;

</description>
      <category>python</category>
      <category>learning</category>
    </item>
    <item>
      <title>Learning Python - Week 3</title>
      <dc:creator>EvanRPavone</dc:creator>
      <pubDate>Fri, 25 Jun 2021 17:02:28 +0000</pubDate>
      <link>https://dev.to/evanrpavone/learning-python-week-4-7i8</link>
      <guid>https://dev.to/evanrpavone/learning-python-week-4-7i8</guid>
      <description>&lt;p&gt;This week I continued to learn the control flow in Python from last week. What I want to focus on in this post is accepting the input from a user. Having a user input information is very easy, all you need is the input function and as the argument for the function you pass in the text or information that you want to see in the console so that the user knows what information they need to put. Here is an example of how to use the input function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name = input('Enter your name: ')
print("Hello there " + name.strip()) # strip removes any white spaces

age = input('Enter your age: ') # input returns a string not an integer
print(name.strip() + "... you are " + str(age.strip()) + " years old")
print(name.strip() + "... you will be " + str(5 + int(age)) + " in 5 years")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The name variable accepts an input of name and the age variable accepts the input of your age. When you run the program it will say:&lt;br&gt;
&lt;code&gt;Enter your name:&lt;/code&gt;&lt;br&gt;
You will enter your name and press enter. The strip function at the end is a way to remove the white space meaning if you happen to add a lot of spaces before you enter your name, it will remove it. Next is the age, when you put your age in it is not an integer, it is a string. So when you press enter it will say &lt;br&gt;
&lt;code&gt;[your name] you are [your age] years old&lt;/code&gt; and then it will say &lt;code&gt;[your name], you will be [add 5 to your age] in five years&lt;/code&gt;.&lt;br&gt;
This was a quick practice and this is what I really like to do when it comes to programming, having a user experience. I am sure I will be able to have a more advanced way of having a user experience in the future but for now this is what I know. I know this is a short post but it was for a good reason. Week 4 will be a whole new section focusing on packages, modules and object oriented programming. It’s still a fun time learning this and I will talk to you guys next week!&lt;/p&gt;

</description>
      <category>python</category>
      <category>learning</category>
    </item>
    <item>
      <title>Learning Python - Week 2</title>
      <dc:creator>EvanRPavone</dc:creator>
      <pubDate>Fri, 18 Jun 2021 15:29:22 +0000</pubDate>
      <link>https://dev.to/evanrpavone/learning-python-week-2-3on</link>
      <guid>https://dev.to/evanrpavone/learning-python-week-2-3on</guid>
      <description>&lt;p&gt;So this week I learned about creating functions, control flow (if else/elif statements) and for loops. It was a slow week for me so I will only be talking about functions and their scope. I only got through a few lessons but next week I will be talking a lot more about these areas.&lt;/p&gt;

&lt;p&gt;For me, creating functions and understanding them seemed a lot easier than learning about functions in the other languages I know even though it is very similar. You would set it up like a function you would see in JavaScript, but for me this looks like a method in Ruby. You would pass a parameter when defining a function and you would pass an argument when you are outputting like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def greet_person(value = “your name”): # passing a parameter of value with a default value
    “””
    DOCSTRING: This returns a greeting / This section is also comments
    INPUT: value
    OUTPUT: Hello… name
    “””
    print(“Hello “ + str(value) + “, this is the greet_person function”)

greet_person()
greet_person(“Evan”)
greet_person(23)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The three greet_persons are different examples. The first will just print the default value and place it in the string, the second will put Evan, and the third will change the integer to a string and put 23. The second and the third are passing in arguments which will change the parameter value and place it in the string. Anything outside of this function would be considered the global scope and anything inside the function is considered the local scope. So if I have a variable of age that is set to 23 and a function increase_age that also has a variable of age that is set to 30, I will not get the increase_age function age if I just print(age) outside of the function. I would end up getting the original age outside of the function, 30.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;age = 23

def increase_age():
    age = 30
    print(age)

print(age) # returns 23 because it calling the age variable outside of the function - global scope
increase_age() # returns 30 because it is inside the function - local scope
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sorry if this got confusing to read but this is what I learned this week. This wasn’t all I learned but this is what really stood out to me. Python is a lot of fun and I am enjoying it. Come back next week!&lt;/p&gt;

</description>
      <category>python</category>
      <category>learning</category>
    </item>
    <item>
      <title>Learning Python - Week 1</title>
      <dc:creator>EvanRPavone</dc:creator>
      <pubDate>Fri, 11 Jun 2021 14:21:31 +0000</pubDate>
      <link>https://dev.to/evanrpavone/learning-python-week-1-2dd0</link>
      <guid>https://dev.to/evanrpavone/learning-python-week-1-2dd0</guid>
      <description>&lt;p&gt;Python… an easy to code, widely used, high-level programming language. I decided to dive into it this week by doing a certification prep course from Udemy. Even though I just started, I am having a lot of fun with it. I am just learning the basics like, variables, data types, basic arithmetic, indexing and slicing strings and a lot more. Next week I will be learning about functions, variable scope and the object oriented side of things. I want to take you on a journey through my python learning experience. What I will be doing is talking about one thing that really stood out to me this week, dictionaries.&lt;/p&gt;

&lt;p&gt;Dictionaries have key value pairs and are not position oriented like lists and tuples, they are key oriented. The format for a dictionary would be &lt;code&gt;variable = {‘key’: ‘value}&lt;/code&gt;. It reminds me of a JSON API page if you have it filled with information. It’s also, from what I can see, very easy to understand and read. It keeps information organized. You can add lists and tuples inside a dictionary too. Here is an example of a dictionary from the course I am taking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_list = [{'Tom': {"salary": 22000, "age": 22, "owns": ['jacket', 'car', 'TV']}},
                {“Mike”: {"salary": 24000, "age": 27, "owns": ["bike", 'laptop', 'boat']}}]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So let’s say that you need to access Mike’s age and show what he owns. Since my_list is a list with a dictionary inside of it you have to give the index of Mike’s dictionary. To do this you can say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Mike_age = my_list[1][“Mike”][“age”]
Mike_owns = my_list[1][“Mike”][“owns”]
print(mike_age)
print(mike_owns)

# -&amp;gt; mike_age returns 27
# -&amp;gt; mike_owns returns a list of [“bike”, “laptop”, “boat”]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You wouldn’t use an index to get mikes information, you would use the key like “Mike” which will return the value &lt;code&gt;{"salary": 24000, "age": 27, "owns": ["bike", 'laptop', 'boat']}&lt;/code&gt;. I used an index because Mike is the second index ([1]) of the list that Tom and Mike are in. Let’s say you now want to remove Mike, this is where the pop() method comes in. The pop() method can remove a key and its values but it can also grab the the key and its values if you set a variable to it like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mike = my_list[1]
# In a list so you have to say which index mike is in [1]
mike_info = mike.pop(“Mike”)
print(my_list) 
# This will just return Tom and his information
print(mike_info)
# This will return mikes info
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was a very fun thing to do this week for my learning experience with Python. You can access everything I learned on my &lt;a href="https://github.com/EvanRPavone/LearningPython"&gt;Github&lt;/a&gt;. I think I will enjoy Python a lot. I know I haven’t gotten far into it but we shall see!&lt;/p&gt;

</description>
      <category>learning</category>
      <category>python</category>
    </item>
    <item>
      <title>Hosting Rails App to Heroku</title>
      <dc:creator>EvanRPavone</dc:creator>
      <pubDate>Thu, 03 Jun 2021 16:01:07 +0000</pubDate>
      <link>https://dev.to/evanrpavone/hosting-rails-app-to-heroku-3318</link>
      <guid>https://dev.to/evanrpavone/hosting-rails-app-to-heroku-3318</guid>
      <description>&lt;p&gt;So you finished your rails application and you want everyone to be able to experience your masterpiece. This is where Heroku comes in. Heroku is an application hosting service that is free to use and is very helpful for those who want to demo and show off their applications. This guide will walk you through on how to install the HerokuCLI and how to push your code to go live. Before we dive into setting up and hosting your Rails Application, make sure you have your github repository for your project setup using &lt;a href="https://codemy.com/git"&gt;Git Version Control&lt;/a&gt;, this is the link I use to set it up.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;Before we begin the installation process, I would go ahead and make a &lt;a href="https://signup.heroku.com/login"&gt;Heroku&lt;/a&gt; account. Installing the Heroku Command Line Interface (CLI) can be easy but if you run into errors, googling the errors will give you the fixes you are looking for. To begin, go to the &lt;a href="https://devcenter.heroku.com/articles/heroku-cli"&gt;Heroku Dev Center&lt;/a&gt; to get the installation instructions for installing the command line interface. Installing this CLI will allow your terminal to connect to Heroku. Depending on what system you are running (MacOS, Windows, Linux), choose your installation process and go through the steps. I am on mac so I would copy the line of code,&lt;br&gt;
&lt;code&gt;brew tap heroku/brew &amp;amp;&amp;amp; brew install heroku&lt;/code&gt;, and paste it into my terminal. Follow any prompts it asks you and you shouldn’t have any issues. To check if you have heroku installed correctly, in your terminal type &lt;code&gt;heroku --version&lt;/code&gt;, if a version pops up, you have HerokuCLI installed!&lt;/p&gt;

&lt;h3&gt;
  
  
  Hosting
&lt;/h3&gt;

&lt;p&gt;First things first, login to heroku in your terminal &lt;code&gt;heroku login&lt;/code&gt;, it will prompt you to press any key to open your browser, do it. Once you are logged in, your terminal will say logged in as (your email). Now you need to create your app by running &lt;code&gt;heroku create&lt;/code&gt;, when you run this command, it will give you the generated link to your application. There is nothing on your page yet because we haven’t pushed your code to Heroku yet. If you want to rename your domain, &lt;code&gt;heroku rename (whatever name you want)&lt;/code&gt;. Now that you created your heroku application, we need to add your ssh keys to heroku. To do this, put &lt;code&gt;heroku keys:add&lt;/code&gt; and follow the prompts, easy enough. Now we need to go into your project gemfile and find sqlite3 (should be at the top), if you don’t see sqlite3 and see pg then you don’t really have to do anything to your gemfile. If you have sqlite3, move it into your development group in your gemfile and put &lt;code&gt;gem ‘pg’ …&lt;/code&gt; where sqlite3 originally was. This is your database, heroku can’t use sqlite3 and postgresql helps with the database for production, make sure you &lt;code&gt;bundle install&lt;/code&gt; and commit your changes to your github repo. You are now ready to push your code to heroku, to do this, put &lt;code&gt;git push heroku (whatever branch, either main/master)&lt;/code&gt;, when you hit enter it will take some time and you will probably run into some errors like &lt;code&gt;You are trying to install ruby-2.6.3 on heroku-20.&lt;/code&gt; Don’t worry, all you need to do is set your stack to heroku-18 by pasting this into your terminal &lt;code&gt;heroku stack:set heroku-18&lt;/code&gt; and then try to push your code to heroku again. If you think that your terminal has froze when pushing to heroku, it hasn't, it just takes some time. Once it is done, your application is now hosted but you aren’t done yet. We need to migrate our database by running &lt;code&gt;heroku run rails db:migrate&lt;/code&gt;. Congrats you have hosted your rails application to Heroku!&lt;/p&gt;

&lt;h3&gt;
  
  
  Heroku Rails Console
&lt;/h3&gt;

&lt;p&gt;Let’s say you have devise for your application and you want to give admin permission to a user. In order to do this, you need to run &lt;code&gt;heroku run rails console&lt;/code&gt;. This will give you your normal rails console but it will be connected to your heroku application. So if you need add a user to admin just put &lt;code&gt;User.find(1).update(admin: true)&lt;/code&gt; into your console. If you want to do other rails stuff just run heroku run rails (whatever). Thanks for taking the time to read through this! I hope it helped and good luck on your future projects!&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>rails</category>
      <category>ruby</category>
      <category>heroku</category>
    </item>
    <item>
      <title>An Easy Admin Panel - Rails 6</title>
      <dc:creator>EvanRPavone</dc:creator>
      <pubDate>Fri, 28 May 2021 15:05:43 +0000</pubDate>
      <link>https://dev.to/evanrpavone/an-easy-admin-panel-rails-6-49a2</link>
      <guid>https://dev.to/evanrpavone/an-easy-admin-panel-rails-6-49a2</guid>
      <description>&lt;p&gt;Having an admin panel in your Rails application is honestly, to me, the best thing to do when it comes to keeping track of your users and giving them permissions. Finding out how to have an admin panel though, that was tough, mainly because I wasn’t searching for the right thing. The &lt;a href="https://github.com/sferik/rails_admin"&gt;rails_admin gem&lt;/a&gt;, so simple but can control so much! The installation and usage is very simple depending on what you are trying to use it on. I should probably tell you, I am using &lt;a href="https://github.com/heartcombo/devise"&gt;devise&lt;/a&gt; with the user having a boolean attribute called admin.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; create_table "users", force: :cascade do |t|
...
    t.boolean "admin", default: false
...
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Installation
&lt;/h4&gt;

&lt;p&gt;The installation all starts with you putting &lt;code&gt;gem ‘rails_admin’&lt;/code&gt; in your gemfile amd running &lt;code&gt;bundle&lt;/code&gt; in your terminal. After you bundle, you will need to run the rails admin generator - &lt;code&gt;rails g rails_admin:install&lt;/code&gt; - doing so will ask you a question, just go ahead and hit enter. Once the generator is done, it will create a new route (“/admin”) and an initializer too.&lt;/p&gt;

&lt;p&gt;You basically have it all working now. Just go to &lt;a href="http://localhost:3000/admin"&gt;http://localhost:3000/admin&lt;/a&gt; and you should be brought to the admin panel! You can navigate this as much as you want to get a feel for where everything is. &lt;/p&gt;

&lt;p&gt;We now need to add some authorization to the initializer. If you go to &lt;code&gt;config/initializers/rails_admin.rb&lt;/code&gt; and add this line of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   config.authorize_with do
      redirect_to main_app.root_path unless warden.user.admin == true
    end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great! Now the only users that can access your admin panel are the ones that are admins. If you need to make yourself and admin go into the rails console with &lt;code&gt;rails c&lt;/code&gt; in the terminal and put in these 3 lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;u = User.first
u.admin = true
u.save 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your user has admin so you can mess around in the admin panel.&lt;/p&gt;

&lt;h4&gt;
  
  
  Navigation to Admin Panel
&lt;/h4&gt;

&lt;p&gt;If you check rails routes you will notice at the very top there is a new route called rails_admin, we will use this to get a navigation button that only the admin can access. Go to where your header or navigation bar is located and add this line of code wherever you want:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%= link_to "Admin Panel", rails_admin_path, class:"btn btn-default mb-2 lg:mr-2 lg:mb-0 block" if admin? %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I have an admin? Helper method so if the user is an admin, they will be able to see the navigation button to the admin panel. In order to do this we will need to go into our helpers in the application_helper.html.erb and add this method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   def admin?
        user_signed_in? &amp;amp;&amp;amp; current_user.admin?
    end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it! You should now have a perfect admin panel that is easy to setup and easy to use!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Partials - Ruby on Rails</title>
      <dc:creator>EvanRPavone</dc:creator>
      <pubDate>Fri, 21 May 2021 16:45:46 +0000</pubDate>
      <link>https://dev.to/evanrpavone/partials-ruby-on-rails-3jjf</link>
      <guid>https://dev.to/evanrpavone/partials-ruby-on-rails-3jjf</guid>
      <description>&lt;p&gt;Partials make your forms and pages easier to manage in Ruby. They are also very easy to setup and customize. In the project I am working on now, I am using a partial that has an if statement saying if there are any Trips show the calendar and all the information, if there are no trips have the user put in a new trip. Like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container m-auto my-4"&amp;gt;
 &amp;lt;% unless current_user.trips.any? %&amp;gt;
   &amp;lt;%= render "trips_cta" %&amp;gt;
 &amp;lt;% else %&amp;gt;
   &amp;lt;%= render "trips_landing", trips: @trips %&amp;gt;
 &amp;lt;% end %&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;_trips_cta.html.erb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="max-w-md my-10 m-auto lg:p-16 bg-white rounded border border-gray-100 text-center shadow"&amp;gt;
    &amp;lt;%= image_tag "schedule.svg", alt: "schedule", width: 300, class: "mb-4" %&amp;gt;
    &amp;lt;h1 class="text-indigo-700 text-2xl mb-6"&amp;gt;It looks like you haven't registered a team yet.&amp;lt;/h1&amp;gt;
    &amp;lt;%= link_to "Register a new team", new_trip_path, class: "btn btn-orange py-3 px-5" %&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;_trips_landing.html.erb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;nav class="bg-white mb-4 shadow rounded"&amp;gt;
    &amp;lt;ul id="nav-tab" class="tabs list-reset flex"&amp;gt;
        &amp;lt;li class="active" data-tab="calendar"&amp;gt;
            &amp;lt;%= link_to "#calendar", class: "tab flex items-center" do %&amp;gt;
                &amp;lt;svg viewBox="0 0 20 20" width="16" height="16" class="fill-current text-grey-100 mr-2"&amp;gt;&amp;lt;title&amp;gt;calendar&amp;lt;/title&amp;gt;&amp;lt;path d="M1 4c0-1.1.9-2 2-2h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V4zm2 2v12h14V6H3zm2-6h2v2H5V0zm8 0h2v2h-2V0zM5 9h2v2H5V9zm0 4h2v2H5v-2zm4-4h2v2H9V9zm0 4h2v2H9v-2zm4-4h2v2h-2V9zm0 4h2v2h-2v-2z"&amp;gt;&amp;lt;/path&amp;gt;&amp;lt;/svg&amp;gt;
                Calendar
            &amp;lt;% end %&amp;gt;
        &amp;lt;/li&amp;gt;
        &amp;lt;li data-tab="all-trips"&amp;gt;
            &amp;lt;%= link_to "#all-trips", class: "tab flex items-center" do %&amp;gt;
                &amp;lt;%= image_tag "plane.svg", alt: "plane", width: 16, height: 16, class: "fill-current text-grey-100 mr-2" %&amp;gt;
                All Trips
            &amp;lt;% end %&amp;gt;
        &amp;lt;/li&amp;gt;
    &amp;lt;/ul&amp;gt;
&amp;lt;/nav&amp;gt;

&amp;lt;div class="bg-white pg-10 border rounded"&amp;gt;
    &amp;lt;div id="all-trips" class="tab-panel p-5"&amp;gt;
        &amp;lt;h1 class="text-xl"&amp;gt;&amp;lt;strong&amp;gt;Trips&amp;lt;/strong&amp;gt;&amp;lt;/h1&amp;gt;

        &amp;lt;% trips.each do |trip| %&amp;gt;
            &amp;lt;div class="flex flex-wrap items-center justify-start p-4 border-b-2 border-grey-100 mb-6"&amp;gt;
                &amp;lt;div class="flex-1 flex justify-between"&amp;gt;
                    &amp;lt;div&amp;gt;
                        &amp;lt;%= link_to trip.team_name, trip, class: "btn-link mr-4"%&amp;gt;
                    &amp;lt;/div&amp;gt;
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the user has no trips, render the call to action partial. If the user has trips, render the landing page.&lt;/p&gt;

&lt;p&gt;Let’s say you want to render a form on a page that already has content on it. You don’t want the file to use up so many lines of code, so you separate them using a partials. I have the trip show page, under the trip info I want to have a comment form but I don’t want to put the form on the show view for trips. Instead I want to make two new files, the form (_form.html.erb) for the comments and where the comments will be rendered after submission (_comments.html.erb). The show page would be setup like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   &amp;lt;%= render 'comments/form' %&amp;gt;
   &amp;lt;div id="comments"&amp;gt;
     &amp;lt;%= render @trip.comments %&amp;gt;
   &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the form will be rendered and when the user submits a comment it will be put in the comments div.&lt;/p&gt;

&lt;p&gt;The form would be setup like you would with any other form (I am using action text so this may look different from yours):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p class="text-sm text-grey-700 my-2"&amp;gt;comment as &amp;lt;%= current_user.name %&amp;gt;&amp;lt;/p&amp;gt;

&amp;lt;%= form_for([@trip, @comment], remote: true) do |f| %&amp;gt;
   &amp;lt;div class="relative"&amp;gt;
       &amp;lt;%= f.rich_text_area :reply, id: "comment_reply_trix", class: 'input h-32 border border-grey-200 p-4 resize-none', placeholder: "add any notes or replies here" %&amp;gt;

       &amp;lt;%= f.submit class: 'btn btn-sm btn-orange block w-full text-center mt-2 lg: mt-0 lg:text-left lg:absolute lg:pin-b lg:pin-r lg:mb-2 lg:mr-2 lg:w-auto lg:inline-flex' %&amp;gt;
   &amp;lt;/div&amp;gt;
&amp;lt;% end %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The comments would be setup like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="flex items-start p-4 mt-4 border rounded"&amp;gt;
   &amp;lt;div class="flex-1 pl-4 flex items-start justify-between"&amp;gt;
       &amp;lt;div class="leading-normal"&amp;gt;
           &amp;lt;p class="text-grey-700 text-xs"&amp;gt;&amp;lt;%= comment.user.name %&amp;gt; commented &amp;lt;%= time_ago_in_words(comment.created_at) %&amp;gt; ago&amp;lt;/p&amp;gt;
           &amp;lt;div class="text-grey-800"&amp;gt;&amp;lt;%= sanitize comment.reply.to_plain_text %&amp;gt;&amp;lt;/div&amp;gt;
       &amp;lt;/div&amp;gt;

       &amp;lt;% if author_of(comment) %&amp;gt;
           &amp;lt;%= link_to "Delete", trip_comment_path(comment.trip, comment), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-red" %&amp;gt;
       &amp;lt;% end %&amp;gt;
   &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want more information regarding rendering , you can visit &lt;a href="https://guides.rubyonrails.org/layouts_and_rendering.html"&gt;Ruby on Rails Guides&lt;/a&gt;. Partials are easy and once you figure it out, your ruby on rails life will hopefully be a lot better.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>View Counter - Rails 6</title>
      <dc:creator>EvanRPavone</dc:creator>
      <pubDate>Thu, 13 May 2021 16:20:38 +0000</pubDate>
      <link>https://dev.to/evanrpavone/view-counter-rails-6-3amh</link>
      <guid>https://dev.to/evanrpavone/view-counter-rails-6-3amh</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Having a view counter is a common thing when it comes to blog posts, tutorials, videos, etc... I wanted to have a view counter for a simple blog post app. I did some quick googling and found out about a gem called &lt;a href="https://github.com/biola/punching_bag"&gt;punching_bag&lt;/a&gt;. It is a very easy gem to use, I will be saying that a lot. Let's get started on showing you how to have a simple view counter for your rails application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Punching Bag
&lt;/h2&gt;

&lt;p&gt;Installing this gem is very easy to do. It all starts with you adding the gem to your gemfile:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gem “punching_bag”&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;After you have the gem in your gemfile you will need to run three commands in your terminal:&lt;/p&gt;

&lt;p&gt;To start off, you need to run &lt;code&gt;bundle install&lt;/code&gt; as usual. After you run bundle you need to run the generator for punching_bag:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails g punching_bag&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will generate a table in your database called punches, which means you need to run &lt;code&gt;rails db:migrate&lt;/code&gt;.&lt;br&gt;
Once you got your database migrated, go into your Post Model and add this line of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;acts_as_punchable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adding this will allow you to get the amount of hits/views on your posts. One last step, and that is to go into your PostController under the show method and have a punch with a request like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@post.punch(request)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congrats you have successfully installed punching_bag and configured it to work with your views. Sweet, let’s add a view counter to your views.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Views
&lt;/h2&gt;

&lt;p&gt;Using the gem in your views is very simple as well. To be honest, using the gem is very simple. For you to see a view counter in your views you need to call the hits like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Views: @post.hits
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it you can now see how many views a Post has. That’s it, simple right? If you want to have your index for the posts to show the most viewed post at the top, that would be in your controller under the index method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@posts = Post.most_hit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now on your index posts page you can see that the post with the most views will be at the top. It’s like adding a scope but the punching bag gem already does that for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The punching bag gem is easy to use and works like a charm. Personally, using this gem is the best way to show views. I hope this helped you for your application. If you need any more information about the gem please visit the github link, &lt;a href="https://github.com/biola/punching_bag"&gt;Punching Bag&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Using Action Text - Rails 6</title>
      <dc:creator>EvanRPavone</dc:creator>
      <pubDate>Fri, 07 May 2021 00:12:42 +0000</pubDate>
      <link>https://dev.to/evanrpavone/using-action-text-rails-6-290o</link>
      <guid>https://dev.to/evanrpavone/using-action-text-rails-6-290o</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Are you trying to figure out how to get a rich text area in your Ruby on Rails Application? Well, that is where Action Text comes in. We will be talking about why you should use Action Text, how to install it, and how to use it in your very own RoR application.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Action Text
&lt;/h2&gt;

&lt;p&gt;Action Text is a great way to bring rich text content to your Rails application. In order to have rich text content you have to install it and it includes trix editor which was the original way. How it works is that any content generated by the action text trix editor is saved in any existing model in the application. For my information about Action Text, you can visit the &lt;a href="https://edgeguides.rubyonrails.org/action_text_overview.html"&gt;Action Text Overview&lt;/a&gt; Page&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Setup
&lt;/h2&gt;

&lt;p&gt;In order to have Action Text in your application you have to follow a few steps. We need to install Active Storage and then Action Text. &lt;/p&gt;

&lt;p&gt;Step 1:&lt;br&gt;
Installing Active Storage...&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails active_storage:install&lt;/code&gt; in your terminal. This is used for embedded images and files.&lt;/p&gt;

&lt;p&gt;Step 2:&lt;br&gt;
Installing Action Text...&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails action_text:install&lt;/code&gt; in your terminal. When action text is being installed it will go ahead and require trix and action text in your application.js file, it will also import the trix stylesheet in app/assets/stylesheets.&lt;/p&gt;

&lt;p&gt;Step 3:&lt;br&gt;
&lt;code&gt;app/assets/stylesheets/application.scss&lt;/code&gt;&lt;br&gt;
Import actiontext.scss file like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import "./actiontext.scss"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 4:&lt;br&gt;
With the trix editor you can import pictures and files. For this to work properly, make sure you uncomment the image processing gem in your gemfile and then run &lt;code&gt;bundle install&lt;/code&gt; or &lt;code&gt;bundle&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After you followed these steps, you will have the action text/trix editor ready to use. Remember, all this information on how to setup Action Text can be found on the Action Text Overview page as well.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to Use
&lt;/h2&gt;

&lt;p&gt;Getting rich text content in your application should be fairly easy now that you have everything installed and setup properly. Now it is time to setup your model, views and controllers.&lt;/p&gt;
&lt;h4&gt;
  
  
  Models
&lt;/h4&gt;

&lt;p&gt;Let's say you want to creat a model called Post, you would normally use your generator like so:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails g model Post title:string body:string&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now that action text is installed, you don't have too. All you have to do now is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails g model Post title:string&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once you have your model generated go into your Post model () and add the rich text field.&lt;br&gt;
&lt;code&gt;app/models/post.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Post &amp;lt; ApplicationRecord
  has_rich_text :body
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don't have to have a body field when you generate your Post because Action Text will take care of that for you by adding the code above.&lt;/p&gt;

&lt;h4&gt;
  
  
  Views
&lt;/h4&gt;

&lt;p&gt;You can setup your form views like you normally would but instead of having&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;div class="field"&amp;gt;
    &amp;lt;%= f.label :body %&amp;gt;
    &amp;lt;%= f.text_field :body %&amp;gt;
  &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you would have&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;div class="field"&amp;gt;
    &amp;lt;%= f.label :body %&amp;gt;
    &amp;lt;%= f.rich_text_area :body %&amp;gt;
  &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's Easy right? When it comes to rendering your outputs to the show page or index page, all you need to do is have&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%= @post.body %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and it will render the rich text content!&lt;/p&gt;

&lt;h4&gt;
  
  
  Controllers
&lt;/h4&gt;

&lt;p&gt;All you have to do now is require :body in your post params.&lt;/p&gt;

&lt;p&gt;That's it, action text is now in your application. Your users can now freely style their posts the way they want too.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
