Code Monkey home page Code Monkey logo

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

Recreating Our Social Media App

Setting up Our Database

Today's Goal is to setup a database for your social media app to save all of your awesome content.

Step 1 - Add a database connection to your application (Hint: It's totally okay to copy the environment.rb file from your Fwitter project.)

Step 2 - Set up your Gemfile with all of your gems - don't forget activerecord and sqlite3 (totally okay to copy from Fwitter again!)

Step 3 - Create a Rakefile and add the necessary lines of code (again, use Fwitter as a reference)

Step 4 - Now we need to modify your Content class so that it inherits from ActiveRecord::Base.

Step 5 - Create a migration for the items table rake db:create_migration NAME="create_content" and get in there to set up your up and down methods. (Look at your Fwitter migration). Don't forget to run your migration with rake db:migrate when you are done! The items table should include columns for:

:username
:content

Step 6 - You'll want to modify your controller action for creating new content. Remember that ActiveRecord is like a hash when creating new content. For Twitter:

Tweet.new("ianstwitterhandle", "My first tweet!")

becomes

tweet = Tweet.new(:username => "ianstwitterhandle", :status => "My first tweet!")
tweet.save

Bonus Challenges

  • Add a page that displays all of the content for a user based on the user. For example, going to "www.fwitter.com/users/ianstwitterhandle" will display all of the tweets where the username is "ianstwitterhandle", "www.fwitter.com/users/taylorswift13" will display all of the tweets where the username is "taylorswift13", etc. You'll need:
    • Dynamic URLs - check out the Sinatra documentation on routes here
    • ActiveRecord's where method - takes a condition as an argument and returns an array of items where the condition is true. ActiveRecord's where

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

hs-social-media-recreation-part-2'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.