Modeling Posts – DIY Twitter Clone #7

Learn how to generate a new Rails model and create the correct database relationships such that user’s can have many posts, and posts must belong to a user. Additionally, we will use activerecord validations to ensure the data is handled correctly, and restrict post content to 140 characters.

Download this project’s files at:


“Clean Code” by Robert C. Martin:
“Game Coding Complete” by Mike McShaffry:
“JavaScript and JQuery” by Jon Ducket:


Creating, updating and managing DevFactor’s large collection of tutorials requires many hours of work on a weekly basis. If you have found our tutorials useful, please support us by subscribing and sharing our videos on social media.

If you have any feedback in regards to how we could improve the channel’s content, editing, or organization feel free to get in touch and make a suggestion!

Subscribe on YouTube:


DevFactor offers high-quality, project based tutorials on web development, game development and software engineering. Simply by subscribing you can gain access to our large library of free programming video tutorials.

DevFactor was started in order to aid anyone regardless of age, race, gender or location to learn how to build, maintain and deploy their own software applications.

#programming #code #devfactor






8 responses to “Modeling Posts – DIY Twitter Clone #7”

  1. Flavius from 1776 Avatar

    Reached this point so far. Twice restarted from scratch and it requires full attention, painstaking at time. But rewarding it is! Andrew deftly, with precision and wit walks you through the web development steps that seemed previously unattainable in such short amount of time and, perhaps more importantly, one could not easily (if at all) find packaged together in such one rapid crash course (back and front end). As we say in French, Andrew has 'dégraissé le mammouth' and thus, made web dev more open and inclusive. Merci!

  2. Claudio Atilano Avatar

    How can I make users share each other's posts? Is there any where I can find this tutorial/info?? Gladly appreciated, loved this tutorial series. Thank you so much!

  3. Shaun Jeffries Avatar

    this this the code I have so far

    <li><a href="/user/<%= current_user.username %>">Profile</a></li>

  4. Shaun Jeffries Avatar

    Hello. Great tutorial by the way! I am getting a error: Routing Error No route matches [GET] "/user/ShaunJ". Can you please help? I'm trying to route the profile on the navigation bar

  5. Andrew Pitzer Avatar

    These are great videos by the way. I am learning a lot about ROR. I am running into an error after running the rake db:migrate after adding the add_index :post, [:user_id, :created_at] This is what the error says:

    Andrews-MacBook-Air:chirp andrewpitzer$ rake db:migrate
    == 20160531221706 CreatePosts: migrating ======================================
    — create_table(:posts)
    -> 0.0020s
    — add_index(:post, [:user_id, :created_at])
    rake aborted!
    StandardError: An error has occurred, this and all later migrations canceled:

    SQLite3::SQLException: no such table: CREATE INDEX "index_post_on_user_id_and_created_at" ON "post" ("user_id", "created_at")
    /Users/andrewpitzer/Desktop/railsdev/Chirp/chirp/db/migrate/20160531221706_create_posts.rb:9:in `change'
    ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: CREATE INDEX "index_post_on_user_id_and_created_at" ON "post" ("user_id", "created_at")
    /Users/andrewpitzer/Desktop/railsdev/Chirp/chirp/db/migrate/20160531221706_create_posts.rb:9:in `change'
    SQLite3::SQLException: no such table:
    /Users/andrewpitzer/Desktop/railsdev/Chirp/chirp/db/migrate/20160531221706_create_posts.rb:9:in `change'
    Tasks: TOP => db:migrate
    (See full trace by running task with –trace)

  6. Malek Zalfana Avatar

    How can I make the posts as images? Do I change content:image? [New to Ruby]

  7. eusdeenius Avatar

    Great tutorial! The only minus for me is, it's very hard to see on a 15" monitor. I have to look as close as a few inches to see it clearly I almost can't see if it's | or ! . Anyway I have a question too. at the end of last video when I changed to current_user.username I can't see anything on the page except the little button. I also get a no route matches error when I try to click the profile button. So far so good but I am stuck here. A help is appreciated.

  8. Yosafat Ariel Avatar

    Hi DevFactor, thank you so much for great tutorial!
    when will the new update tutorial for DIY Twitter clone available?

Leave a Reply

Your email address will not be published. Required fields are marked *