<?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: aalcantara1</title>
    <description>The latest articles on DEV Community by aalcantara1 (@aalcantara1).</description>
    <link>https://dev.to/aalcantara1</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%2F3673059%2Fbef6ced9-b87e-4dcf-9ae5-4a1f673eb9b4.png</url>
      <title>DEV Community: aalcantara1</title>
      <link>https://dev.to/aalcantara1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aalcantara1"/>
    <language>en</language>
    <item>
      <title>3/30/2026</title>
      <dc:creator>aalcantara1</dc:creator>
      <pubDate>Mon, 30 Mar 2026 23:38:02 +0000</pubDate>
      <link>https://dev.to/aalcantara1/3302026-5c9m</link>
      <guid>https://dev.to/aalcantara1/3302026-5c9m</guid>
      <description>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Can use the ideas generator but need to change the draft:resources to scaffold and make a couple of edits - for example, there are differences in the way that you identify the foreign key column &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;rails c to load a console in the terminal. press q in a console to get back to main&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scopes define class level method (not instances). &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>03/28/2026</title>
      <dc:creator>aalcantara1</dc:creator>
      <pubDate>Sun, 29 Mar 2026 14:38:01 +0000</pubDate>
      <link>https://dev.to/aalcantara1/03282026-10p3</link>
      <guid>https://dev.to/aalcantara1/03282026-10p3</guid>
      <description>&lt;p&gt;&lt;strong&gt;General process after rails generate scaffold and before rails db:migrate&lt;/strong&gt;&lt;br&gt;
In Rails, the scaffold command is just the starting point. The generator gives you a rough draft, and your job is to review and customize it before it touches the database.&lt;/p&gt;

&lt;p&gt;Here is the usual process:&lt;/p&gt;

&lt;p&gt;Generate the scaffold&lt;br&gt;
 rails generate scaffold Comment author:references photo:references body:text&lt;br&gt;
Look at what Rails created A scaffold usually creates:&lt;br&gt;
a migration&lt;br&gt;
a model&lt;br&gt;
a controller&lt;br&gt;
views&lt;br&gt;
routes&lt;br&gt;
tests/spec files&lt;br&gt;
Edit the migration first This is the most important step before migrating. Review the generated migration and fix anything the generator could not know about your app’s business rules.&lt;/p&gt;

&lt;p&gt;Common things to change:&lt;/p&gt;

&lt;p&gt;add null: false where blank values should not be allowed&lt;br&gt;
add default: values if needed&lt;br&gt;
fix foreign keys when the association name does not match the table name&lt;br&gt;
make sure column types are correct&lt;br&gt;
add indexes or uniqueness constraints if needed&lt;br&gt;
Example:&lt;/p&gt;

&lt;p&gt;t.references :author, null: false, foreign_key: { to_table: :users }&lt;br&gt;
 t.references :photo, null: false, foreign_key: true&lt;br&gt;
 t.text :body, null: false&lt;/p&gt;

&lt;p&gt;Why this matters:&lt;/p&gt;

&lt;p&gt;the scaffold only guesses&lt;br&gt;
it does not know your custom association names&lt;br&gt;
it does not know which fields should be required&lt;br&gt;
Edit the model After the migration looks right, update the model so Rails understands the relationships and rules.&lt;/p&gt;

&lt;p&gt;Common things to add:&lt;/p&gt;

&lt;p&gt;belongs_to&lt;br&gt;
has_many&lt;br&gt;
class_name:&lt;br&gt;
foreign_key:&lt;br&gt;
validates&lt;br&gt;
enum&lt;br&gt;
scopes&lt;br&gt;
counter_cache: true&lt;br&gt;
Example:&lt;/p&gt;

&lt;p&gt;class Comment &amp;lt; ApplicationRecord&lt;br&gt;
   belongs_to :author, class_name: "User", counter_cache: true&lt;br&gt;
   belongs_to :photo, counter_cache: true&lt;/p&gt;

&lt;p&gt;validates :body, presence: true&lt;/p&gt;

&lt;p&gt;scope :default_order, -&amp;gt; { order(created_at: :asc) }&lt;br&gt;
 end&lt;br&gt;
If needed, edit related models too If you added a new belongs_to, you often also need the matching has_many on the other model.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;class User &amp;lt; ApplicationRecord&lt;br&gt;
   has_many :comments, foreign_key: :author_id, dependent: :destroy&lt;br&gt;
 end&lt;br&gt;
And:&lt;/p&gt;

&lt;p&gt;class Photo &amp;lt; ApplicationRecord&lt;br&gt;
   has_many :comments, dependent: :destroy&lt;br&gt;
 end&lt;br&gt;
Review for naming mismatches This is a very common source of bugs.&lt;/p&gt;

&lt;p&gt;If you use a custom association name like:&lt;/p&gt;

&lt;p&gt;author instead of user&lt;br&gt;
fan instead of user&lt;br&gt;
owner instead of user&lt;br&gt;
then you usually need:&lt;/p&gt;

&lt;p&gt;foreign_key: { to_table: :users } in the migration&lt;br&gt;
class_name: "User" in the model&lt;br&gt;
Optionally commit the generated files before editing This is not required, but it is a very good habit.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;git add -A&lt;br&gt;
 git commit -m "Generated Comments scaffold"&lt;br&gt;
Then after your edits:&lt;/p&gt;

&lt;p&gt;git add -A&lt;br&gt;
 git commit -m "Configured Comment migration and model"&lt;br&gt;
This makes it easier to separate:&lt;/p&gt;

&lt;p&gt;what Rails generated&lt;br&gt;
what you changed&lt;br&gt;
Then migrate&lt;br&gt;
 rails db:migrate&lt;br&gt;
Short version&lt;br&gt;
A good rule of thumb is:&lt;/p&gt;

&lt;p&gt;generate scaffold&lt;br&gt;
inspect generated files&lt;br&gt;
fix the migration&lt;br&gt;
fix the model&lt;br&gt;
add/update related associations&lt;br&gt;
then migrate&lt;br&gt;
What you should especially check before migrating&lt;br&gt;
Before you run rails db:migrate, ask yourself:&lt;/p&gt;

&lt;p&gt;Are the foreign keys pointing to the correct tables?&lt;br&gt;
Should any columns have null: false?&lt;br&gt;
Should any columns have a default value?&lt;br&gt;
Do I need class_name: because I used a custom association name?&lt;br&gt;
Do I need validations in the model to match the database rules?&lt;br&gt;
Do I need matching has_many associations in other models?&lt;br&gt;
In one sentence&lt;br&gt;
The general process is: use scaffold to generate the rough draft, then manually review and customize the migration and models before running the migration.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>First Post</title>
      <dc:creator>aalcantara1</dc:creator>
      <pubDate>Sun, 21 Dec 2025 23:14:58 +0000</pubDate>
      <link>https://dev.to/aalcantara1/first-post-31mk</link>
      <guid>https://dev.to/aalcantara1/first-post-31mk</guid>
      <description>&lt;p&gt;test&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;h1&amp;gt;Hello, World!&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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