Code Monkey home page Code Monkey logo

hs-social-media-recreation-part-3's Introduction

Recreating Our Social Media App

Adding a User Model

Today's Goal is to incorporate a User model into your social media apps.

Step 1 - Create a migration to create a users table (as always, refer to Fwitter as a guide). The user should have columns for username and email.

Step 2 - Create a User model that inherits from ActiveRecord::Base. Remember, if you have a table called users, you need a model called User.

Step 3 - It's your content's job to keep track of which user it belongs to, but it needs to keep track by the user's id, not the username. Create another migration that removes the username column from your content and adds a column called user_id (again, let Fwitter be your guide) Run the migrations using rake db:migrate

Step 4 - Your content model no longer responds to a method called username. Instead, it responds to a method called user which returns the user object. That user object responds to a method called username. Update your views so that you're calling content.user.username instead of content.username.

Step 5 - Any content that we created before won't have a user_id associated with it, which will cause errors when running our application. We can fix this by updating the data using tux. Boot up tux in the terminal and destory your previously created content like so: Tweet.destroy_all

Step 6 - Create a form to create new users. Setup the necessary controller actions so that you can add Users to your database - it should look similar to the way you create new content.

Step 7 - Modify the way your content is created. This will happen in two steps: * First, update the form so that a user enters their id number instead of their username . * In the controller, new content should no longer be created with a username. Instead, it should be created with a user_id.

Bonus Challenges

  • It's kind of lame that a user has to memorize their id number to be able to post content. Update this for a better user experience by adding a drop-down menu of every user in our database. The drop-down should display their username, but the value should be their user_id.
  • Add another model/relationship to your app to expand functionality. Some ideas:
    • Comments
    • Hashtags
    • Retweets
    • Think carefully about the relationship between hashtags and tweets.

View Recreating Our Social Media App on Learn.co and start learning to code for free.

hs-social-media-recreation-part-3's People

Contributors

ipc103 avatar victhevenot avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.