<?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: Andrew Ackerman</title>
    <description>The latest articles on DEV Community by Andrew Ackerman (@ackers93).</description>
    <link>https://dev.to/ackers93</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%2F139498%2F25948794-78a8-477c-a609-c996a1c2665a.png</url>
      <title>DEV Community: Andrew Ackerman</title>
      <link>https://dev.to/ackers93</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ackers93"/>
    <language>en</language>
    <item>
      <title>Beginner's guide to the Devise gem.</title>
      <dc:creator>Andrew Ackerman</dc:creator>
      <pubDate>Mon, 26 Aug 2019 21:18:31 +0000</pubDate>
      <link>https://dev.to/ackers93/beginner-s-guide-to-the-devise-gem-35hm</link>
      <guid>https://dev.to/ackers93/beginner-s-guide-to-the-devise-gem-35hm</guid>
      <description>&lt;p&gt;Recently I've been working on a Rails app to track work-out progress. &lt;/p&gt;

&lt;p&gt;As you read in the title, this post is about using the Devise Gem, and I'll be working through using it at it's simplest form, to create a resource that I wished I'd had when I first tried it out. &lt;/p&gt;

&lt;p&gt;The Devise Gem is users for User Authentication, It creates sign-up and sign-in forms, it also can be used to create user accounts for privacy. (I'm sure it can do more things, but this is how I'm using it. )&lt;/p&gt;

&lt;p&gt;So as with all other gems, you'll need to install in the usual way by adding to your Gemfile, &lt;code&gt;gem 'Devise'&lt;/code&gt; Then run &lt;code&gt;bundle install&lt;/code&gt; in your terminal. After you've done that, you'll need to run the generator. &lt;code&gt;rails generate devise:install&lt;/code&gt;. &lt;br&gt;
That command installs an initializer that will print a lot of instructions, the only one we need to focus on right now is adding a default URL for the Devise Mailer. You can use the suggested one for the sake of this application.&lt;/p&gt;

&lt;p&gt;Next, we need to create our Devise model, you can name it anything, (e.g. User, Admin, Member or Staff) depending on your purpose. I'll be using "User", thus I'll run in my terminal, &lt;code&gt;rails generate devise user&lt;/code&gt;, following that up with &lt;code&gt;rails db:migrate&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The first action you should take is to ensure that your Rails routes are configured for Devise, which is done by adding the following to your &lt;code&gt;config/routes.rb&lt;/code&gt; file,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;devise_for&lt;/span&gt; &lt;span class="ss"&gt;:stages&lt;/span&gt;
&lt;span class="n"&gt;root&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"stages#index"&lt;/span&gt;
&lt;span class="c1"&gt;# "stages" can be replaced by whatever you name your controller, it's just what I needed to name my controller.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create all the necessary routes for authentication of your application, and then lead to the main index page.&lt;/p&gt;

&lt;p&gt;In order to make your parts of your application unavailable to people without an account, go into their controllers and before your methods begin, add the following helper,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;before_action&lt;/span&gt; &lt;span class="ss"&gt;:authenticate_user!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Something to be aware of, is to make sure that your helper matches your Devise model (User, Admin, etc.)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The three most important helpers for Devise are as follows,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;user_signed_in?&lt;/span&gt;
&lt;span class="c1"&gt;# I used this to show the user’s email address in the top Navigation bar, and depending on their status to show “Log In” or “Log Out” options.&lt;/span&gt;
&lt;span class="n"&gt;user_session&lt;/span&gt;
&lt;span class="c1"&gt;# Used to create the Log In occurrence, which remains until I’m logged out, in which case it destroys that session.&lt;/span&gt;
&lt;span class="n"&gt;current_user&lt;/span&gt;
&lt;span class="c1"&gt;#This is used here to display the User's email in the navigation bar.&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% if &lt;/span&gt;&lt;span class="n"&gt;user_signed_in?&lt;/span&gt; &lt;span class="sx"&gt;%&amp;gt;
    &amp;lt;%= current_user.email %&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ul&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"dropdown-menu"&lt;/span&gt; &lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"menu"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= link_to 'Profile', edit_user_registration_path %&amp;gt;&amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;link_to&lt;/span&gt; &lt;span class="s1"&gt;'Log out'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;destroy_user_session_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;method: :delete&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&amp;gt;
&amp;lt;% else %&amp;gt;
          &amp;lt;li&amp;gt;&amp;lt;%= link_to 'Log In', new_user_session_path %&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= link_to 'Sign Up', new_user_registration_path %&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;% end %&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;current_user&lt;/code&gt; helper is also used in my controllers, stopping the user from accessing and editing any other user's data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;new&lt;/span&gt;
    &lt;span class="vi"&gt;@stage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;
    &lt;span class="vi"&gt;@stage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;allowed_params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="vi"&gt;@stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;
      &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;stages_path&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
      &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="s1"&gt;'new'&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;edit&lt;/span&gt;
    &lt;span class="vi"&gt;@stage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;update&lt;/span&gt;
    &lt;span class="vi"&gt;@stage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="vi"&gt;@stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update_attributes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;allowed_params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;stages_path&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
      &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="s1"&gt;'edit'&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;destroy&lt;/span&gt;
    &lt;span class="vi"&gt;@stage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="vi"&gt;@stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;destroy&lt;/span&gt;
    &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;stages_path&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, every method in my Stages controller has to be authenticated through the Devise Gem's &lt;code&gt;current_user&lt;/code&gt; helper.&lt;/p&gt;

&lt;p&gt;Another useful aspect of Devise is that running &lt;code&gt;$ rails generate devise:views users&lt;/code&gt; will create all the necessary views for signing up, logging in, password changes and account changes. As an example, here's what Devise creates for a sign-up page,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Sign up&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%=&lt;/span&gt; &lt;span class="na"&gt;form_for&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="na"&gt;resource&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="na"&gt;as:&lt;/span&gt; &lt;span class="na"&gt;resource_name&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="na"&gt;url:&lt;/span&gt; &lt;span class="na"&gt;registration_path&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="na"&gt;resource_name&lt;/span&gt;&lt;span class="err"&gt;))&lt;/span&gt; &lt;span class="na"&gt;do&lt;/span&gt; &lt;span class="err"&gt;|&lt;/span&gt;&lt;span class="na"&gt;f&lt;/span&gt;&lt;span class="err"&gt;|&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%=&lt;/span&gt; &lt;span class="na"&gt;render&lt;/span&gt; &lt;span class="err"&gt;"&lt;/span&gt;&lt;span class="na"&gt;devise&lt;/span&gt;&lt;span class="err"&gt;/&lt;/span&gt;&lt;span class="na"&gt;shared&lt;/span&gt;&lt;span class="err"&gt;/&lt;/span&gt;&lt;span class="na"&gt;error_messages&lt;/span&gt;&lt;span class="err"&gt;",&lt;/span&gt; &lt;span class="na"&gt;resource:&lt;/span&gt; &lt;span class="na"&gt;resource&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"field"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%=&lt;/span&gt; &lt;span class="na"&gt;f.label&lt;/span&gt; &lt;span class="na"&gt;:email&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;br&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%=&lt;/span&gt; &lt;span class="na"&gt;f.email_field&lt;/span&gt; &lt;span class="na"&gt;:email&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="na"&gt;autofocus:&lt;/span&gt; &lt;span class="na"&gt;true&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="na"&gt;autocomplete:&lt;/span&gt; &lt;span class="err"&gt;"&lt;/span&gt;&lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="err"&gt;"&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"field"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%=&lt;/span&gt; &lt;span class="na"&gt;f.label&lt;/span&gt; &lt;span class="na"&gt;:password&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%&lt;/span&gt; &lt;span class="na"&gt;if&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;minimum_password_length&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;em&amp;gt;&lt;/span&gt;(&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%=&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;minimum_password_length&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; characters minimum)&lt;span class="nt"&gt;&amp;lt;/em&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%&lt;/span&gt; &lt;span class="na"&gt;end&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;br&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%=&lt;/span&gt; &lt;span class="na"&gt;f.password_field&lt;/span&gt; &lt;span class="na"&gt;:password&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="na"&gt;autocomplete:&lt;/span&gt; &lt;span class="err"&gt;"&lt;/span&gt;&lt;span class="na"&gt;new-password&lt;/span&gt;&lt;span class="err"&gt;"&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"field"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%=&lt;/span&gt; &lt;span class="na"&gt;f.label&lt;/span&gt; &lt;span class="na"&gt;:password_confirmation&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;br&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%=&lt;/span&gt; &lt;span class="na"&gt;f.password_field&lt;/span&gt; &lt;span class="na"&gt;:password_confirmation&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="na"&gt;autocomplete:&lt;/span&gt; &lt;span class="err"&gt;"&lt;/span&gt;&lt;span class="na"&gt;new-password&lt;/span&gt;&lt;span class="err"&gt;"&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"actions"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%=&lt;/span&gt; &lt;span class="na"&gt;f.submit&lt;/span&gt; &lt;span class="err"&gt;"&lt;/span&gt;&lt;span class="na"&gt;Sign&lt;/span&gt; &lt;span class="na"&gt;up&lt;/span&gt;&lt;span class="err"&gt;"&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%&lt;/span&gt; &lt;span class="na"&gt;end&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%=&lt;/span&gt; &lt;span class="na"&gt;render&lt;/span&gt; &lt;span class="err"&gt;"&lt;/span&gt;&lt;span class="na"&gt;devise&lt;/span&gt;&lt;span class="err"&gt;/&lt;/span&gt;&lt;span class="na"&gt;shared&lt;/span&gt;&lt;span class="err"&gt;/&lt;/span&gt;&lt;span class="na"&gt;links&lt;/span&gt;&lt;span class="err"&gt;"&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, there's a lot of work already done for you, which means you only have to blend it into the style of whatever you're creating.&lt;/p&gt;

&lt;p&gt;I believe that's all I'm going to cover in this post without running the risk of going against my opening statement of blogging about Devise in "it's simplest form". Hopefully this helps someone else understand this incredible useful gem! &lt;/p&gt;

&lt;p&gt;If you have any suggestions for other simple ways to use it that are beginner-friendly, please comment them down below! &lt;/p&gt;

</description>
      <category>gems</category>
      <category>devise</category>
      <category>rails</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Solving Issues in PostgreSQL. (Lessons in Debugging)</title>
      <dc:creator>Andrew Ackerman</dc:creator>
      <pubDate>Thu, 22 Aug 2019 23:41:35 +0000</pubDate>
      <link>https://dev.to/ackers93/solving-issues-in-postgresql-lessons-in-debugging-2ggg</link>
      <guid>https://dev.to/ackers93/solving-issues-in-postgresql-lessons-in-debugging-2ggg</guid>
      <description>&lt;p&gt;Last week I had the joy of spilling water on my computer, which turned it off rather quickly. Thankfully I was able to get it into an Apple Store and they dried it out and the biggest loss was the screen, meaning I have to have it eternally plugged into a monitor now, but it could have been far worse. Once I was back into work, I got ready to begin, opened my terminal, and tried running my Rails app, only to have this issue appear:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Started GET &lt;span class="s2"&gt;"/"&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; ::1 at 2019-08-21 09:15:43 &lt;span class="nt"&gt;-0700&lt;/span&gt;
could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket &lt;span class="s2"&gt;"/tmp/.s.PGSQL.5432"&lt;/span&gt;?
 excluded from capture: DSN not &lt;span class="nb"&gt;set

&lt;/span&gt;PG::ConnectionBad &lt;span class="o"&gt;(&lt;/span&gt;could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket &lt;span class="s2"&gt;"/tmp/.s.PGSQL.5432"&lt;/span&gt;?
&lt;span class="o"&gt;)&lt;/span&gt;:

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

&lt;/div&gt;



&lt;p&gt;As &lt;em&gt;PG&lt;/em&gt; is an abbreviation for Postgres, My first thought is that there’s an issue with how PostgreSQL (my database) is working, so after a quick trip to Stack Overflow to relearn Postgres commands I thought I’d try the ol’ “Have you tried turning it off and on again?” So I restarted PostgreSQL, like so,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$brew&lt;/span&gt; services restart postgresql
Stopping &lt;span class="sb"&gt;`&lt;/span&gt;postgresql&lt;span class="sb"&gt;`&lt;/span&gt;... &lt;span class="o"&gt;(&lt;/span&gt;might take a &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;==&amp;gt;&lt;/span&gt; Successfully stopped &lt;span class="sb"&gt;`&lt;/span&gt;postgresql&lt;span class="sb"&gt;`&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;label: homebrew.mxcl.postgresql&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;==&amp;gt;&lt;/span&gt; Successfully started &lt;span class="sb"&gt;`&lt;/span&gt;postgresql&lt;span class="sb"&gt;`&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;label: homebrew.mxcl.postgresql&lt;span class="o"&gt;)&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Unfortunately, this did not work, And I was greeted with the same error. I headed back to Stack Overflow and tried the first rwo pages of results, all to no avail. So I decided then to seek help from my employer, (&lt;a class="mentioned-user" href="https://dev.to/andrewculver"&gt;@andrewculver&lt;/a&gt;
) and he reminded me of a previous PostgreSQL issue I had encountered, in which PostgreSQL creates a &lt;code&gt;postmaster.pid&lt;/code&gt; file, which doesn't get dealt with when a computer experiences a hard shutdown, which in turn stops PostgreSQL from running again, because it believes it's already running. Thus the &lt;code&gt;postmaster.pid&lt;/code&gt; file needs to be deleted in order for PostgreSQL to get up and running again, So we did the following,&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;Run &lt;code&gt;brew info postgresql&lt;/code&gt;. You should see a reference to &lt;code&gt;pg_ctl -D &amp;gt;/usr/local/var/postgres start&lt;/code&gt;. &lt;em&gt;Don’t run that&lt;/em&gt;, You just want to 
confirm that the path is &lt;code&gt;/usr/local/var/postgres&lt;/code&gt;.
&lt;em&gt;Actually&lt;/em&gt; do this:&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;cd /usr/local/var/postgres&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;ls&lt;/code&gt; 
You should see a &lt;code&gt;postmaster.pid&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;rm ./postmaster.pid&lt;/code&gt;. You shouldn’t have any trouble deleting 
this file, but if you do, run &lt;code&gt;sudo rm ./postmaster.pid&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;brew services start postgresql&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;While this may have helped the previous issue I'd had before, unfortunately, the same error message appeared, so it was time to do some deeper digging.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Solution
&lt;/h1&gt;

&lt;p&gt;Firstly we made our way into &lt;code&gt;cd /usr/local/var/log/&lt;/code&gt;, once inside, we listed the contents like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls
&lt;/span&gt;postgres.log    redis.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next wanted to check some of the recent log entries without displaying everything, so used &lt;code&gt;tail&lt;/code&gt; to print out the last 10 lines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;tail&lt;/span&gt; ./postgres.log 
  Reason: image not found
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.63.dylib
  Referenced from: /usr/local/opt/postgresql/bin/postgres
  Reason: image not found
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.63.dylib
  Referenced from: /usr/local/opt/postgresql/bin/postgres
  Reason: image not found
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.63.dylib
  Referenced from: /usr/local/opt/postgresql/bin/postgres
  Reason: image not found
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Finally we saw our issue!&lt;/em&gt; The postmaster.pid wasn't the issue, but instead a dynamic library for Unicode and globalization called &lt;code&gt;icu4c&lt;/code&gt;, which was affecting our PostgreSQL processes. So, using Homebrew we uninstalled &lt;code&gt;postgresql&lt;/code&gt; and reinstalled &lt;code&gt;icu4c&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;brew uninstall postgresql
Uninstalling /usr/local/Cellar/postgresql/11.2... &lt;span class="o"&gt;(&lt;/span&gt;3,186 files, 35.4MB&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;icu4c
Updating Homebrew...

&lt;span class="c"&gt;#I'm not going to past all the output because it goes on forever, but icu4c is reinstalled!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we installed PostgreSQL and restarted it's processes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew install postgresql
==&amp;gt; Installing dependencies for postgresql: openssl and readline
==&amp;gt; Installing postgresql dependency: openssl
==&amp;gt; Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2s.mojave.bottle.tar.gz
==&amp;gt; Downloading from https://akamai.bintray.com/c4/c4a762d719c2be74ac686f1aafabb32f3c5d5ff3a98935c4925a1ddb9c750ee1?__gda__=exp=1566501434~hmac=b709fcc5ffd01de96a07acdb294be279
######################################################################## 100.0%

#Again, a lot more output then I'm going to post here, but it ends with these two options.

To have launchd start postgresql now and restart at login:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  pg_ctl -D /usr/local/var/postgres start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first option sounded like what we wanted, so we went with that.&lt;/p&gt;

&lt;p&gt;So that's it!  Andrew said that this has happened to him every few months for years, so we wanted to post something that would help anyone else who is seeing the same uninformative error message. Even if a mis-linked dynamic library isn't your specific issue, the contents of that logfile are likely to tell you what's wrong. If you need help debugging this issue, and the steps above didn't help, just post the output of your log file in the comments below! In fact, even if you understand the error message right away, please paste it in the comments anyway just so we can build a catalog of all the different reasons PostgreSQL isn't automatically restarting for different people. It might help someone else! Hopefully this helps someone else having the same issue! If you have any pointers or suggestions for other ways of solving the problem, I'd love to know! &lt;/p&gt;

</description>
      <category>postgres</category>
      <category>database</category>
      <category>unix</category>
      <category>debugging</category>
    </item>
    <item>
      <title>Lessons on Rails Routing and MVC Layouts.</title>
      <dc:creator>Andrew Ackerman</dc:creator>
      <pubDate>Thu, 02 May 2019 01:26:35 +0000</pubDate>
      <link>https://dev.to/ackers93/lessons-on-rails-routing-and-mvc-layouts-4c9j</link>
      <guid>https://dev.to/ackers93/lessons-on-rails-routing-and-mvc-layouts-4c9j</guid>
      <description>&lt;p&gt;Since March this year, I've been in the process of learning Rails, I've been on Treehouse learning Ruby in my spare time for around 2 years so decided it was time to learn how Rails works and begin to understand it in all it's "magic", This is hopefully  the first of a few blog posts to document my learning curve and give me (and others) a resource I can come back to later when I forget how things work.&lt;/p&gt;

&lt;p&gt;A fundamental part of Rails is the MVC layout, this stands for Model, View and Controller which are the three main elements of Rails applications.&lt;/p&gt;

&lt;p&gt;To begin, let's just create a simple app, I prefer using Postgres as I've had troubles with Gemfile dependencies for the default Sqlite3 (something else for me to learn to deal with later) so I'll specify that in my command into Terminal.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails new demo --database=postgresql&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will create our app named "demo" in the current directory, the next thing to do is to shift into that application folder using Terminal. &lt;code&gt;cd demo&lt;/code&gt; The general rule for order of creating a MVC layout is to follow the order of the letters, beginning with your model, moving onto your view(s) and finishing with your controller, but this isn't a hard and fast rule, just a common practice, for ease of this post, I'm going to break this rule and go MCV, but there are plenty of stackoverflow posts to show why it's more commonly done MVC. So let's begin by creating our Model &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A Model defines what something is, and what abilities it has.&lt;/strong&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I'm going to create a simple food inventory, maybe for knowing how much food we have left in our cupboard.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails generate model Food name:string size:integer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will create the following migration file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CreateFoods&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Migration&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;5.2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;change&lt;/span&gt;
    &lt;span class="n"&gt;create_table&lt;/span&gt; &lt;span class="ss"&gt;:foods&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:name&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:size&lt;/span&gt;

      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timestamps&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This seems good to go for our simple application so run &lt;code&gt;rake db:migrate&lt;/code&gt; in order to run the migration.&lt;/p&gt;

&lt;p&gt;Now that we've created our Model, let's go ahead and generate our controller.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A Controller handles all the complex logic, rendering partials, saving things to the database and giving feedback to the user.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;rails generate controller foods&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Notice that the controller is labeled as a plural of the model, and there is no uppercase letters. If it is done the wrong way they may have trouble connecting to each other.&lt;/p&gt;

&lt;p&gt;This will generate the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FoodsController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, it's not really doing anything, so we need to add some methods which we can use to modify and add to our application, like so...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FoodsController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;show&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;new&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;edit&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;update&lt;/span&gt; 
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;destroy&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="kp"&gt;private&lt;/span&gt;
   &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;allowed_params&lt;/span&gt;
       &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:food&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;permit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
   &lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are all the methods we would need for a typical application, and while they're empty now, we will come back and add to them in a little while. For the meantime, we need to link our Model to our Controller we do this by going into our &lt;code&gt;/config/routes.rb&lt;/code&gt; file. and add the Rails helper method &lt;code&gt;resources :foods&lt;/code&gt; to our list. This will create the routes necessary for our FoodsController. This could also be written long form, with each route specified.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s2"&gt;"/foods"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"foods#index"&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s2"&gt;"/foods/:id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"foods#show"&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s2"&gt;"/foods/new"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"foods#new"&lt;/span&gt;
  &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="s2"&gt;"/foods"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"foods#create"&lt;/span&gt;  &lt;span class="c1"&gt;# usually a submitted form&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s2"&gt;"/foods/:id/edit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"foods#edit"&lt;/span&gt;
  &lt;span class="n"&gt;put&lt;/span&gt; &lt;span class="s2"&gt;"/foods/:id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"foods#update"&lt;/span&gt; &lt;span class="c1"&gt;# usually a submitted form&lt;/span&gt;
  &lt;span class="n"&gt;delete&lt;/span&gt; &lt;span class="s2"&gt;"/foods/:id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"foods#destroy"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a good time to explain Routing. Although generally you will only have &lt;code&gt;resources :id&lt;/code&gt; there is a way to see your list of Routes. Go back to your terminal and enter &lt;code&gt;rake routes&lt;/code&gt;. and you'll be able to see the above list.. I found it took a while for me to get used to reading the routes in that format, but it's really useful once you put some time in!&lt;/p&gt;

&lt;p&gt;A URL in a browser sends a request to our router (config/routes.rb) which will analyze the URL and find and send to matching action in matching controller, which will try to match with the view.&lt;/p&gt;

&lt;p&gt;Now that we've seen how the model and controller work, and now that the controller is searching for a view, let's create all the necessary views.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A View is a template, something shown to the user.. most often a HTML document.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In your editor find your "app/views/foods" folder and create the file "index.html.erb", follow suite with a "show", "edit" and "new". &lt;/p&gt;

&lt;p&gt;To begin with, let's create our "new" view. First, we need to edit our FoodsController, adding to our new method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;new&lt;/span&gt;
    &lt;span class="vi"&gt;@food&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Food&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a new instance of our food Model and assigns it to the &lt;code&gt;@food&lt;/code&gt; instance variable. Now we head over to "new.html.erb" and create our page. We just want a simple form to add a food name and size to our database..&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= form_for @food do |f| %&amp;gt;

  &amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;label&lt;/span&gt; &lt;span class="ss"&gt;:name&lt;/span&gt;  &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;br&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= f.text_field :name %&amp;gt; &amp;lt;br&amp;gt;

  &amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;label&lt;/span&gt; &lt;span class="ss"&gt;:size&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;br&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= f.text_field :size %&amp;gt; &amp;lt;br&amp;gt;

  &amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;submit&lt;/span&gt; &lt;span class="s1"&gt;'Save Food Item'&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% end &lt;/span&gt;&lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it's time to start your server, go to &lt;a href="http://localhost:3000/foods/new"&gt;http://localhost:3000/foods/new&lt;/a&gt; and have a look. Your form will be there, and you'll be able to add to your database, but without other routes defined yet. You can't see, edit or delete that data and trying to save the information will throw a "Template is missing" error for "foods/create" so let's add that action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;
    &lt;span class="vi"&gt;@food&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Food&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;allowed_params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="vi"&gt;@food&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;
      &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;foods_path&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
      &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="s1"&gt;'new'&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So this method take the instance of the food model we entered into our form and attempt to save it, if it is successful we'll be redirected to our index method (via &lt;code&gt;foods_path&lt;/code&gt;) or if not, it will direct us back to our New form.&lt;br&gt;
Because you'll be sent to our Index page, it'll be helpful if we created one now. To begin, add to your index method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;
    &lt;span class="vi"&gt;@foods&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Food&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This take all the foods from the database and lists them on our Index views page, which we need to edit to all in to do that. Add the following to your view.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% @foods.each &lt;/span&gt;&lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;food&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="sx"&gt;%&amp;gt;
  &amp;lt;p&amp;gt;&lt;/span&gt;
    &lt;span class="no"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= food.name %&amp;gt;&amp;lt;br&amp;gt;
    Size: &amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;food&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;size&lt;/span&gt; &lt;span class="sx"&gt;%&amp;gt; | &amp;lt;%= link_to 'Edit', edit_food_path(food) %&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;
&amp;lt;% end %&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This loops through each of your database items and places then in a separate paragraph. It's a good idea to be trying these new functions as you go in your browser to see if you run into any problems. As you can see, I've also begun my edit function on the previous code sample for the sake of saving space. It's time to give functionality to that edit button in the Controller, incase we need to update our inventory as we use items.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;edit&lt;/span&gt;
    &lt;span class="vi"&gt;@food&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Food&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives the Edit function the ability to search through the database for the correct item to edit, identified by the &lt;code&gt;(params[:id])&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For your view, just copy and paste from your "new.html.erb" into your "edit.html.erb" This will provide the form to Edit (with profiled fields) but if you try it out, you'll find it won't save the updated values, showing us our error is that theres no Template for our FoodsController's Update function, so it's now time to add that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;update&lt;/span&gt;
    &lt;span class="vi"&gt;@food&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Food&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="vi"&gt;@food&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update_attributes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;allowed_params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;foods_path&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
      &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="s1"&gt;'new'&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works in a similar way to our Edit and Create Functions combined. Finding the item, updating it's attributes, and depending on whether or not it can be saved, redirects us to where we need to be.&lt;/p&gt;

&lt;p&gt;Two routes that are useful to have on our index page are Adding an item, and deleting an item. Editing your index.html.erb file like so will adding these links.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= link_to 'Add Food', new_food_path %&amp;gt;

&amp;lt;% @foods.each do |food| %&amp;gt;
  &amp;lt;p&amp;gt;
    Name: &amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;food&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt; &lt;span class="sx"&gt;%&amp;gt;&amp;lt;br&amp;gt;&lt;/span&gt;
    &lt;span class="no"&gt;Size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= food.size %&amp;gt; | &amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;link_to&lt;/span&gt; &lt;span class="s1"&gt;'Edit'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;edit_food_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;food&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= link_to 'Delete Item', food, method: :delete %&amp;gt;
  &amp;lt;/p&amp;gt;
&amp;lt;% end %&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Add Food link will work automatically, but your Destroy method in your FoodsController will need to be edited. It should read..&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;destroy&lt;/span&gt;
    &lt;span class="vi"&gt;@food&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Food&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="vi"&gt;@food&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;destroy&lt;/span&gt;
    &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;foods_path&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After adding this, go ahead and delete one of your records, and see that it deletes it and immediately redirects us back to our &lt;code&gt;foods_path&lt;/code&gt; which is our index page.&lt;/p&gt;

&lt;p&gt;The final method we need to add is our Show method. We'll us this to allow us to look at each item individually. Where our name attribute is shown in index.html.erb, edit it the following way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;    &lt;span class="no"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= link_to food.name, food_path(food) %&amp;gt;&amp;lt;br&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will lead up to our show method (as you can see if you use your &lt;code&gt;rake routes&lt;/code&gt; command in terminal again) Now we need to give it a view to display in "show.html.erb"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= @food.name %&amp;gt;&amp;lt;/h1&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will display the name of a variable as a header, which has yet to be defined. All we need to do is edit our Controller's Show function to search for our item and assign it to the variable our view is wanting to display.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;show&lt;/span&gt;
    &lt;span class="vi"&gt;@food&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Food&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once this is done. we have all of our Routes accounted for and now we have this basic setup, it's just a case of duplicating it's ideas for more complex tasks.&lt;/p&gt;

&lt;p&gt;I hope this was as helpful for you as it was for me writing it! I would appreciate any feedback, corrections and questions as I'm excited to keep learning and learning to teach these concepts.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>newbie</category>
      <category>mvc</category>
    </item>
    <item>
      <title>Learning about Unix File Permissions</title>
      <dc:creator>Andrew Ackerman</dc:creator>
      <pubDate>Mon, 01 Apr 2019 22:13:38 +0000</pubDate>
      <link>https://dev.to/ackers93/learning-about-unix-file-permissions-54h</link>
      <guid>https://dev.to/ackers93/learning-about-unix-file-permissions-54h</guid>
      <description>&lt;p&gt;I've recently been tasked with testing out a small program which my employer wrote up. To be really brief about it, it is a piece of code that allows me to type in my terminal &lt;code&gt;t 'sample text'&lt;/code&gt; and it'll save it to an intake file which I can find and manipulate in my Text Editor. It's basically a way of taking notes without having to leave Terminal, keeping me focused on whatever the task at hand happens to be. &lt;/p&gt;

&lt;p&gt;This was going well for a short while until somehow I deleted the bin. file from my dropbox, where it's currently storing all the information. After restoring the file, as soon as I attempted to use the program again, Terminal would spit out the following:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;-bash: /Users/ackerman/Dropbox/Thoughts/bin/t: Permission denied&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Having never encountered this before, I began looking in all the wrong places.. I thought something was wrong with my directory, then that maybe something was wrong with the Ruby code it's written in or else I had somehow broken my dropbox.. All of my theories were soon proven wrong, but unfortunately, I didn't really know how to figure the solution out. So after trying for some time, I decided to swallow my pride and ask my employer. Thankfully he was more than willing to help me out, so I'm hoping I can pass on his knowledge to help others who may encounter this!&lt;/p&gt;

&lt;p&gt;Every file in Unix has three different permission options:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Owner Permissions:&lt;/strong&gt; This determines the actions that the Owner can perform on the file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Group Permissions:&lt;/strong&gt; This determines the actions that a member of the group who owns the file, can perform.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Other (world) Permissions:&lt;/strong&gt; This shows the actions that any other user can perform on the file.&lt;/p&gt;

&lt;p&gt;So the best way to get a handle on what we need to change is to see the what the file we're working with's permissions are set to.&lt;/p&gt;

&lt;p&gt;Once in the directory with the correct file. run the &lt;code&gt;ls -la&lt;/code&gt; command if the file you need to modify is hidden, or simply the or &lt;code&gt;ls -l&lt;/code&gt; command, if it's not. This will output something similar to this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;drwxr-xr-x    4 ackerman  staff    128 Feb 19 11:32 mydir&lt;br&gt;
-rw-r--r--    1 ackerman  staff    157 Feb 19 15:22 myfile&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;First thing to notice is that the first character is either a &lt;code&gt;d&lt;/code&gt; or an &lt;code&gt;-&lt;/code&gt; which denotes whether the file is &lt;code&gt;d&lt;/code&gt; a Directory or &lt;code&gt;-&lt;/code&gt; a file.The next 3 characters designate &lt;strong&gt;owner&lt;/strong&gt; permissions, the three after that show the &lt;strong&gt;group&lt;/strong&gt; permissions and the final three in that segment show the permission for the &lt;strong&gt;world/other.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Reading them is quite simple.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;r:&lt;/strong&gt; Indicates the user can &lt;strong&gt;read&lt;/strong&gt; the file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;w:&lt;/strong&gt; Indicates the user can &lt;strong&gt;write&lt;/strong&gt; to the file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;x:&lt;/strong&gt; Indicates whether the user can &lt;strong&gt;execute&lt;/strong&gt; the file.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The rest of the information in the line isn't super pertinent to what I'm covering here. But for a greater understanding there are plenty of resources available if you need.&lt;/p&gt;

&lt;h1&gt;
  
  
  But how do I change the permissions?
&lt;/h1&gt;

&lt;p&gt;In order to change permissions, you'll have use the &lt;code&gt;chmod&lt;/code&gt; (change mode) command, followed by whichever category you wish to change access for. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a:&lt;/strong&gt; All Users&lt;br&gt;
&lt;strong&gt;u:&lt;/strong&gt; The Owner user&lt;br&gt;
&lt;strong&gt;g:&lt;/strong&gt; The Owner Group&lt;br&gt;
&lt;strong&gt;o:&lt;/strong&gt; Others (Neither U, or G)&lt;/p&gt;

&lt;p&gt;This is coupled with one or more of three different operators.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;+&lt;/strong&gt; Adds the designated permission to a file or directory.&lt;br&gt;
&lt;strong&gt;-&lt;/strong&gt; Removes the permission.&lt;br&gt;
&lt;strong&gt;=&lt;/strong&gt; Sets the permissions.&lt;/p&gt;

&lt;p&gt;And followed by the permission action we covered before. (&lt;strong&gt;r, w or x&lt;/strong&gt;). Here are some examples of this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;chmod a+r &lt;em&gt;myfile&lt;/em&gt;&lt;/strong&gt; files are readable by all&lt;br&gt;
&lt;strong&gt;chmod a-r &lt;em&gt;myfile&lt;/em&gt;&lt;/strong&gt; files cancels the ability for all to read the file&lt;br&gt;
&lt;strong&gt;chmod a-rwx &lt;em&gt;myfile&lt;/em&gt;&lt;/strong&gt; cancels all access for all&lt;br&gt;
&lt;strong&gt;chmod g+rw &lt;em&gt;myfile&lt;/em&gt;&lt;/strong&gt; files give the group read and write permission&lt;br&gt;
&lt;strong&gt;chmod u+rwx &lt;em&gt;myfile&lt;/em&gt;&lt;/strong&gt; files give the owner all permissions&lt;br&gt;
&lt;strong&gt;chmod og+rw &lt;em&gt;myfile&lt;/em&gt;&lt;/strong&gt; files give the world and the group read and write permission &lt;/p&gt;

&lt;p&gt;This is all well and good for changing &lt;strong&gt;file_ permissions, but what about __directories&lt;/strong&gt;? These need to be changed with a numbering system, and using it this way is called the absolute form. Each number is indicative of whom is getting permission to do what.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;400    Read by owner&lt;br&gt;
200    Write by owner&lt;br&gt;
100    Execute by owner&lt;br&gt;
040    Read by group&lt;br&gt;
020    Write by group&lt;br&gt;
010    Execute by group&lt;br&gt;
004    Read by others&lt;br&gt;
002    Write by others&lt;br&gt;
001    Execute by others&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In order to use them, simply add them and place them after your &lt;code&gt;chmod&lt;/code&gt; command and the file/directory name. This isn't just for directories, and can simply be used for editing individual files. You also don't have to worry about learning all these numbers, as you can use a &lt;a href="http://permissions-calculator.org"&gt;Permissions Calculator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In example, here's what it took to fix my problem. All I wanted to do was to make it so that the Owner could Read (400), Write (200) and Execute (100) the file, So I ran &lt;code&gt;chmod 700 ./t&lt;/code&gt;. When I used the &lt;code&gt;ls -la&lt;/code&gt; command after this. You can see the file has been changed to allow me as the Owner full permission to do all I needed to the file. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;-rwx------@ 1 ackerman  staff    63 Mar 29 09:46 t&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I hope this has been of some help to anyone looking for a basic understanding of Unix Permissions. Feel free to let me know if you have any questions! &lt;/p&gt;

</description>
      <category>unix</category>
    </item>
  </channel>
</rss>
