<?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: pbohea</title>
    <description>The latest articles on DEV Community by pbohea (@pbohea).</description>
    <link>https://dev.to/pbohea</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%2F2979657%2Fcd3182d2-77b5-4f94-9b11-641aa2e3cfcb.png</url>
      <title>DEV Community: pbohea</title>
      <link>https://dev.to/pbohea</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pbohea"/>
    <language>en</language>
    <item>
      <title>Pundit Authorization</title>
      <dc:creator>pbohea</dc:creator>
      <pubDate>Fri, 11 Apr 2025 15:13:26 +0000</pubDate>
      <link>https://dev.to/pbohea/pundit-authorization-3c8e</link>
      <guid>https://dev.to/pbohea/pundit-authorization-3c8e</guid>
      <description>&lt;p&gt;def show&lt;br&gt;
    authorize &lt;a class="mentioned-user" href="https://dev.to/photo"&gt;@photo&lt;/a&gt;&lt;br&gt;
 end&lt;/p&gt;

&lt;p&gt;When you pass the authorize method an instance of Photo:&lt;/p&gt;

&lt;p&gt;It assumes there is a class called PhotoPolicy in app/policies.&lt;/p&gt;

&lt;p&gt;It assumes there is a method called current_user.&lt;/p&gt;

&lt;p&gt;It passes current_user as the first argument and whatever you pass to authorize (in this case, photo) as the second argument to a new instance of PhotoPolicy.&lt;/p&gt;

&lt;p&gt;It calls a method named after the action with a ? appended on the new policy instance.&lt;/p&gt;

&lt;p&gt;If it gets back false, it raises Pundit::NotAuthorizedError.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>authorization</category>
      <category>policy</category>
      <category>development</category>
    </item>
    <item>
      <title>Enum</title>
      <dc:creator>pbohea</dc:creator>
      <pubDate>Fri, 04 Apr 2025 18:08:54 +0000</pubDate>
      <link>https://dev.to/pbohea/enum-20d0</link>
      <guid>https://dev.to/pbohea/enum-20d0</guid>
      <description>&lt;p&gt;class FollowRequest &amp;lt; ApplicationRecord&lt;br&gt;
  belongs_to :recipient, class_name: "User"&lt;br&gt;
  belongs_to :sender, class_name: "User"&lt;/p&gt;

&lt;p&gt;enum :status, { pending: "pending", rejected: "rejected", accepted: "accepted" }&lt;br&gt;
end&lt;/p&gt;

&lt;p&gt;the "enum" enumerates a list of values that can be stored in the "status" column, allowing you to call the status on the model instance. example below&lt;/p&gt;

&lt;h1&gt;
  
  
  assume follow_request is a valid and pending
&lt;/h1&gt;

&lt;p&gt;follow_request.accepted? # =&amp;gt; false&lt;br&gt;
follow_request.accepted! # sets status to "accepted" and saves&lt;/p&gt;

</description>
      <category>backend</category>
      <category>rails</category>
      <category>code</category>
      <category>programming</category>
    </item>
    <item>
      <title>belongs_to default</title>
      <dc:creator>pbohea</dc:creator>
      <pubDate>Thu, 03 Apr 2025 01:36:09 +0000</pubDate>
      <link>https://dev.to/pbohea/belongsto-default-5gm0</link>
      <guid>https://dev.to/pbohea/belongsto-default-5gm0</guid>
      <description>&lt;p&gt;In standard Rails applications, the default is opposite: belongs_to adds an automatic validation to foreign key columns enforcing the presence of a valid value unless you explicitly add the option optional: true.&lt;/p&gt;

&lt;p&gt;So remember — if you’re ever in the situation of:&lt;/p&gt;

&lt;p&gt;-you’re trying to save a record&lt;/p&gt;

&lt;p&gt;-the save is failing&lt;/p&gt;

&lt;p&gt;-you’re doing the standard debugging technique of printing out zebra.errors.full_messages&lt;/p&gt;

&lt;p&gt;-you’re seeing an inexplicable validation error message saying that a foreign key column is blank&lt;/p&gt;

&lt;p&gt;-now you know where the validation is coming from: belongs_to adds it automatically&lt;/p&gt;

&lt;p&gt;-so figure out why you’re not providing a valid foreign key (usually it is because the parent object failed to save for its own validation reasons)&lt;/p&gt;

</description>
      <category>rails</category>
      <category>developers</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Add Index</title>
      <dc:creator>pbohea</dc:creator>
      <pubDate>Thu, 03 Apr 2025 01:16:25 +0000</pubDate>
      <link>https://dev.to/pbohea/add-index-50d3</link>
      <guid>https://dev.to/pbohea/add-index-50d3</guid>
      <description>&lt;p&gt;adding index to non-foreign key columns enables faster lookups. i.e. if you add index to the email column for the User model, instead of searching every single user top to bottom, it will seek out that value. &lt;/p&gt;

&lt;p&gt;when creating model or scaffold, you don't need to define index for foreign key columns&lt;/p&gt;

</description>
      <category>database</category>
      <category>programming</category>
      <category>performance</category>
    </item>
    <item>
      <title>g scaffold vs g model</title>
      <dc:creator>pbohea</dc:creator>
      <pubDate>Thu, 03 Apr 2025 00:57:50 +0000</pubDate>
      <link>https://dev.to/pbohea/g-scaffold-vs-g-model-3j51</link>
      <guid>https://dev.to/pbohea/g-scaffold-vs-g-model-3j51</guid>
      <description>&lt;p&gt;The question you have to answer now is: for each of these tables, do you want to generate a scaffold or do you just want to generate a model? How do we figure that out?&lt;/p&gt;

&lt;p&gt;My usual rule of thumb:&lt;/p&gt;

&lt;p&gt;If I will need routes and controller/actions for users to be able to CRUD records in the table, then I probably want to generate scaffold. (At least some of the generated routes/actions/views will go unused. I need to remember to go back and at least disable the routes, and eventually delete the entire RCAVs, at some point; or I risk introducing security holes.)&lt;/p&gt;

&lt;p&gt;If the model will only be used on the backend, e.g. by other models, then I probably want to generate model. For example, a Month model where I will create all twelve records once in db/seeds.rb does not require routes, MonthsController, app/views/months/, etc.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>find_by() &amp; find()</title>
      <dc:creator>pbohea</dc:creator>
      <pubDate>Tue, 01 Apr 2025 16:31:38 +0000</pubDate>
      <link>https://dev.to/pbohea/findby-4f67</link>
      <guid>https://dev.to/pbohea/findby-4f67</guid>
      <description>&lt;p&gt;find_by() returns a single instance, not an array.&lt;/p&gt;

&lt;p&gt;Movie.find_by(id:3).title will return the title of the movie with id 3. if the id doesnt exist, it returns "nil".&lt;/p&gt;

&lt;p&gt;find() also returns a single instance, but assumes you are searching for primary key (ID).&lt;br&gt;
Movie.find(3).title returns the title of movie with id 3. if id doesnt exist, it returns 404 error. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>rails</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Test Post Day 1</title>
      <dc:creator>pbohea</dc:creator>
      <pubDate>Wed, 26 Mar 2025 23:29:31 +0000</pubDate>
      <link>https://dev.to/pbohea/test-post-day-1-13g2</link>
      <guid>https://dev.to/pbohea/test-post-day-1-13g2</guid>
      <description>&lt;p&gt;Test&lt;/p&gt;

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