<?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: austinmei5</title>
    <description>The latest articles on DEV Community by austinmei5 (@austinmei5).</description>
    <link>https://dev.to/austinmei5</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%2F1001362%2F0b0fee9a-a342-4323-83dc-ab15e05704e2.png</url>
      <title>DEV Community: austinmei5</title>
      <link>https://dev.to/austinmei5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/austinmei5"/>
    <language>en</language>
    <item>
      <title>JS Range Function</title>
      <dc:creator>austinmei5</dc:creator>
      <pubDate>Sun, 05 Feb 2023 09:26:02 +0000</pubDate>
      <link>https://dev.to/austinmei5/js-range-function-20ei</link>
      <guid>https://dev.to/austinmei5/js-range-function-20ei</guid>
      <description>&lt;p&gt;const range = (start, end, step = 1) =&amp;gt; {&lt;br&gt;
  let output = [];&lt;/p&gt;

&lt;p&gt;if (typeof end === 'undefined') {&lt;br&gt;
    end = start;&lt;br&gt;
    start = 0;&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;for (let i = start; i &amp;lt; end; i += step) {&lt;br&gt;
    output.push(i);&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;return output;&lt;br&gt;
};&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>howto</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Attr Accessor</title>
      <dc:creator>austinmei5</dc:creator>
      <pubDate>Wed, 25 Jan 2023 00:35:00 +0000</pubDate>
      <link>https://dev.to/austinmei5/attr-accessor-1c5b</link>
      <guid>https://dev.to/austinmei5/attr-accessor-1c5b</guid>
      <description>&lt;p&gt;attr_accessor :color&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creates a set of 'set' and 'get' methods for 'color'&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;attr_reader :color&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creates a 'get' method for 'color'&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;attr_writer :color&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creates a 'set' method for 'color'&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;def initialize(color)&lt;br&gt;
 @color = color&lt;br&gt;
end&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;initializes a variable that cannot be changed later when creating an instance of an object&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>help</category>
      <category>debugging</category>
      <category>programming</category>
    </item>
    <item>
      <title>Notice and Alerts</title>
      <dc:creator>austinmei5</dc:creator>
      <pubDate>Sat, 21 Jan 2023 01:06:14 +0000</pubDate>
      <link>https://dev.to/austinmei5/notice-and-alerts-35p6</link>
      <guid>https://dev.to/austinmei5/notice-and-alerts-35p6</guid>
      <description>&lt;p&gt;Create 2 partials for notices and alerts:&lt;/p&gt;

&lt;p&gt;&amp;lt;%= notice %&amp;gt;&lt;/p&gt;

&lt;p&gt;&amp;lt;%= alert %&amp;gt;&lt;/p&gt;

&lt;p&gt;We can also create a single partial and pass in the css_class:&lt;/p&gt;

&lt;p&gt;&amp;lt;%= message %&amp;gt;&lt;/p&gt;

&lt;p&gt;Logic in Application Layout:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;% if notice.present? %&amp;gt;
    &amp;lt;%= render "shared/flash", message: notice, css_class: "success" %&amp;gt;
  &amp;lt;% end %&amp;gt;

  &amp;lt;% if alert.present? %&amp;gt;
    &amp;lt;%= render "shared/flash", message: alert, css_class: "danger" %&amp;gt;
  &amp;lt;% end %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>gratitude</category>
    </item>
    <item>
      <title>Sign in/Sign out</title>
      <dc:creator>austinmei5</dc:creator>
      <pubDate>Sat, 21 Jan 2023 00:24:39 +0000</pubDate>
      <link>https://dev.to/austinmei5/sign-insign-out-4o3n</link>
      <guid>https://dev.to/austinmei5/sign-insign-out-4o3n</guid>
      <description>&lt;p&gt;In the nav bar, paste the following to create sign in/sign out functionality:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul class="navbar-nav"&amp;gt;
  &amp;lt;% if user_signed_in? %&amp;gt;
    &amp;lt;li class="nav-item"&amp;gt;
      &amp;lt;%= link_to "Edit profile", edit_user_registration_path, class: "nav-link" %&amp;gt;
    &amp;lt;/li&amp;gt;

    &amp;lt;li class="nav-item"&amp;gt;
      &amp;lt;%= link_to "Sign out", destroy_user_session_path, class: "nav-link", method: :delete %&amp;gt;
    &amp;lt;/li&amp;gt;
  &amp;lt;% else %&amp;gt;
    &amp;lt;li class="nav-item"&amp;gt;
      &amp;lt;%= link_to "Sign in", new_user_session_path, class: "nav-link" %&amp;gt;
    &amp;lt;/li&amp;gt;

    &amp;lt;li class="nav-item"&amp;gt;
      &amp;lt;%= link_to "Sign up", new_user_registration_path, class: "nav-link" %&amp;gt;
    &amp;lt;/li&amp;gt;
  &amp;lt;% end %&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To enforce sign in/out, we add a before action in ApplicationController:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add: "before_action :authenticate_user!"&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Bootstrap Setup</title>
      <dc:creator>austinmei5</dc:creator>
      <pubDate>Sat, 21 Jan 2023 00:23:52 +0000</pubDate>
      <link>https://dev.to/austinmei5/bootstrap-setup-38kc</link>
      <guid>https://dev.to/austinmei5/bootstrap-setup-38kc</guid>
      <description>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Remove scaffold css from assets folder&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the shared folder, create a file called "_cdn_assets.html.erb"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add bootstrap to the cdn assets file.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;







&lt;ol&gt;
&lt;li&gt;Render "shared/cdn_assets" in the head of the application.html.erb file&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>saas</category>
      <category>productivity</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Annotate Gem</title>
      <dc:creator>austinmei5</dc:creator>
      <pubDate>Fri, 20 Jan 2023 23:27:00 +0000</pubDate>
      <link>https://dev.to/austinmei5/annotate-gem-3ab8</link>
      <guid>https://dev.to/austinmei5/annotate-gem-3ab8</guid>
      <description>&lt;p&gt;The Annotate Gem adds detailed annotations in the model file for each data model. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;First, add "gem 'annotate'" to the development group in the Gemfile.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once installed, run 'annotate --models' in the terminal to annotate all models.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(cont.) If this fails, run 'bundle exec annotate' instead.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can also do 'rails g annotate:install' to create a rake task that will create annotations anytime we do rails db:migrate.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>discuss</category>
      <category>education</category>
      <category>productivity</category>
      <category>career</category>
    </item>
    <item>
      <title>Scaffold Tutorial</title>
      <dc:creator>austinmei5</dc:creator>
      <pubDate>Fri, 20 Jan 2023 07:16:57 +0000</pubDate>
      <link>https://dev.to/austinmei5/scaffold-tutorial-29eg</link>
      <guid>https://dev.to/austinmei5/scaffold-tutorial-29eg</guid>
      <description>&lt;p&gt;When considering Draft Resource vs. Scaffold, think about which RCAVs we need for our app. (Create, edit, update, destroy actions). &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Command to generate: "rails generate scaffold task text:string status:string owner:references"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(cont.) Using 'owner:references' instead of 'owner_id:string' initializes the 'owner' column as a foreign key column in the database. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the model migration file, update any default values. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Typically, we might also want to add 'index: true' to the :owner column in the migration file. However, this should be set to true by default in current versions of Rails.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Since we used :owner instead of :user, we need to add to the foreign key: 'foreign_key: { to_table: :users }'&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(cont.) If we do not do this step, the migration will fail. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the 'tasks' model, we also need to update the belongs_to relation: 'belongs_to :owner, class_name: "User"'. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(cont.) In the users model, we add the following association: 'has_many :own_tasks, class_name: "Task", foreign_key: "owner_id"'.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(cont.) belongs_to should always have a matching has_many association.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Repeat for any other models in the app.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>beginners</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Devise Tutorial</title>
      <dc:creator>austinmei5</dc:creator>
      <pubDate>Fri, 20 Jan 2023 06:58:26 +0000</pubDate>
      <link>https://dev.to/austinmei5/devise-tutorial-43k5</link>
      <guid>https://dev.to/austinmei5/devise-tutorial-43k5</guid>
      <description>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Add Devise gem in Gemfile and configure the app according to the instructions in the terminal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(cont.) Add 'config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }' to the 'development.rb' file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create the users model using: 'rails generate devise user username'. This is a simple model that only tracks a user's username and nothing else. More variables and their data types can be added if necessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update default values in the users migration file. Make sure default values are appropriate.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add indexes where appropriate in the migration file. Example: "add_index" :users, :username,        unique: true". &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(cont.) The index above provides a database level constraint on uniqueness. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add case-insensitive column for username. Add 'enable_extension("citext")' to the top of change method in the migration file. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(cont.) Change &lt;strong&gt;username and email&lt;/strong&gt; columns in migration file to 't.citext' instead of 't.string'. This adds database level protection for case insensitivity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once all default values, indexes, and case-insensitivities are updated, migrate the model with 'rails db:migrate'&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;MISC - if we at any point drop the database, we need to use 'rails db:create' to re-add the database since we are using Postgre. &lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Photogram Industrial</title>
      <dc:creator>austinmei5</dc:creator>
      <pubDate>Sun, 15 Jan 2023 01:04:11 +0000</pubDate>
      <link>https://dev.to/austinmei5/photogram-industrial-362l</link>
      <guid>https://dev.to/austinmei5/photogram-industrial-362l</guid>
      <description>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Keep Devise gem outside of the development group in the Gemfile. We want to use Devise in our production app. Any gems used for development only will fall under the development group.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Gem groups allow us to specify Gems used in production vs. development&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Command + K clears terminal&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Under the 'change' method of the migration file, include: enable_extension("citext")&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then change username and email from 'string' to 'citext'. Most developers forget to do this! This removes case sensitivity from these two columns in the database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reminder that 'git acm ""' is an appdev shortcut for: "git add -A; git commit -m"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;typically, we generate users model first using Devise&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the command 'annotate --models' to use the Annotate Gem. This creates annotations in each of the Model files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use 'rails g annonate:install' to annotate models anytime we run 'rails db:migrate' &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reminder: each belongs_to should have an inverse has_many&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://blog.arkency.com/how-to-add-a-default-value-to-an-existing-column-in-a-rails-migration/" rel="noopener noreferrer"&gt;https://blog.arkency.com/how-to-add-a-default-value-to-an-existing-column-in-a-rails-migration/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wrap .destroy_all commands in the following manner:&lt;br&gt;
if Rails.env.development?&lt;br&gt;
User.destroy_all&lt;br&gt;
FollowRequest.destroy_all&lt;br&gt;
end&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keep in mind that we need to destroy children objects before parent objects&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Unique use of shuttle operator: &lt;br&gt;
photos.fans &amp;lt;&amp;lt; follower # pushing follower into the fans collection of the Photo&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;creates a record in the join table, adding user to collection of users under the 'likes' table &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Helper Methods: Part 2</title>
      <dc:creator>austinmei5</dc:creator>
      <pubDate>Sat, 07 Jan 2023 05:12:59 +0000</pubDate>
      <link>https://dev.to/austinmei5/helper-methods-part-2-1a2f</link>
      <guid>https://dev.to/austinmei5/helper-methods-part-2-1a2f</guid>
      <description>&lt;p&gt;form_with(url: movies_path)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;3 variations of finding an active record item:
@the_movie = Movie.where(id: params.fetch(:id)).first&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;@the_movie = Movie.find_by(id: params.fetch(:id))&lt;/p&gt;

&lt;p&gt;@the_movie = Movie.find(params.fetch(:id))&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;nested hashes&lt;/li&gt;
&lt;/ul&gt;


&lt;br&gt;
  Red&lt;br&gt;
  

&lt;p&gt;Blue&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;Submit&lt;br&gt;
&amp;lt;/form&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;top level key is zebra, information/attributes is stored in sub-hashes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ex: { :movie =&amp;gt; { :title =&amp;gt; "Some title", :description =&amp;gt; "Some desc" }}&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using this format, we can complete mass assignment in the controller. ex:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;movie_attributes = params.fetch(:movie)&lt;/p&gt;

&lt;p&gt;@movie = Movie.new(movie_attributes)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;in order to do this however, we need to whitelist the :title and :description columns as strong parameters:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;movie_attributes = params.require(:movie).permit(:title, :description)&lt;/p&gt;

&lt;p&gt;@movie = Movie.new(movie_attributes)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;finally, in the routes page, we can represent all standard routes using a single line of code:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;resources :movies&lt;/p&gt;

</description>
      <category>community</category>
      <category>discuss</category>
      <category>developers</category>
    </item>
    <item>
      <title>Refactoring Helper Methods: Part 1</title>
      <dc:creator>austinmei5</dc:creator>
      <pubDate>Fri, 06 Jan 2023 23:20:02 +0000</pubDate>
      <link>https://dev.to/austinmei5/refactoring-helper-method-part-1-5hii</link>
      <guid>https://dev.to/austinmei5/refactoring-helper-method-part-1-5hii</guid>
      <description>&lt;ul&gt;
&lt;li&gt;refactoring routes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;get "/", controller: "movies", action: "index"&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;more shorthand syntax for a route&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;get "/" =&amp;gt; "movies#index"&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;we can shorten this even further for the root because there is only 1 path:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;root "movies#index"&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;"rails routes" command shows all defined routes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;we can name routes with "as:"&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;get "/movies/:id" =&amp;gt; "movies#show", as: :details&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;we can then access this specific route with an argument:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;details_path(42) --&amp;gt; "/movies/42"&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using route names reduces redundancy when updating URL names! Always refer to URLs using route names from now on&lt;/li&gt;
&lt;/ul&gt;




&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We can truncate @a_movie.id to @a_movie when using movie_path&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;on View templates, we should use paths (movie_path)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;on Server side, we should use URLs (movie_url)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When possible, remove render statements if class and definition matches&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Replace:&lt;br&gt;
. &lt;a href="&amp;lt;%=%20new_movie_path%20%&amp;gt;%22&amp;gt;Add%20a%20new%20movie&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;%0A&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;With:&amp;lt;br&amp;gt;%0A.%20&amp;lt;%=%20link_to%20%22Add%20a%20new%20movie%22,%20new_movie_path%20%&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;%0A&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Replace:&amp;lt;br&amp;gt;%0Amovie_path(a_movie)&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;%0A&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;With:&amp;lt;br&amp;gt;%0Aa_movie&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;%0A&amp;lt;/ul&amp;gt;%0A"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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