Skip to content

Instantly share code, notes, and snippets.

@kareemgrant
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save kareemgrant/8f75efb3facdaeefd726 to your computer and use it in GitHub Desktop.

Select an option

Save kareemgrant/8f75efb3facdaeefd726 to your computer and use it in GitHub Desktop.

Revisions

  1. kareemgrant revised this gist Jun 6, 2015. 1 changed file with 2 additions and 8 deletions.
    10 changes: 2 additions & 8 deletions adding_data_to_your_views_sinatra.markdown
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ## Basic ActiveRecord Sinatra
    ## Displaying Database Data in your Sinatra Application

    ### Goals

    @@ -17,10 +17,4 @@
    Hint: We went through these steps using the sinatra_todo application, so reference that application to guide your through this assignement


    2. ***VERY IMPORTANT:*** If you haven't already done so; please ensure that your laptop is correctly set up for Rails development by following the setup instructions found on [installrails.com](http://installrails.com/). If this is not completed before next class, you ***will*** run into issues and you may fall behind.


    ### Recommended Activity

    Read up on HTML forms:
    [http://www.w3schools.com/html/html_forms.asp](http://www.w3schools.com/html/html_forms.asp)
    ***VERY IMPORTANT:*** If you haven't already done so; please ensure that your laptop is correctly set up for Rails development by following the setup instructions found on [installrails.com](http://installrails.com/). If this is not completed before next class, you ***will*** run into issues and you may fall behind.
  2. kareemgrant revised this gist Jun 6, 2015. 1 changed file with 10 additions and 3 deletions.
    13 changes: 10 additions & 3 deletions adding_data_to_your_views_sinatra.markdown
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,20 @@

    ### Goals

    1. Understand how to create and access a database with ActiveRecord
    1. Understand how you can take information from your database and display it to your users

    2. See how this database will be used and accessed from your Sinatra application
    2. Create a has_many relationship in your application

    ### Assignment

    1. Create a new sinatra app called ``sinatra_blog`` and add a database to the app using the steps specified in class. Add a ``users`` table to the database with the following fields: email and full_name. Then create a ``User`` model in the app that can be used to create (read, update or delete) new user records using activerecord. The assignment will be considered complete when you are able to succesfully create new users in IRB (as specified in class).
    1. Continue using the ``sinatra_blog`` you created during the last homework assignment. Add a ``posts`` table to your application (remember: you will need to use migrations) and establish a has_many relationship between users and posts, where ``users can have many posts``. The ``posts`` table should have three fields: title, body and a foreign key.
    2. Once you have established the has_many relationship at the database level, you will also need to communicate the relationship at the application level. After that is done, use irb and activerecord to add posts to users.
    3. In your application, add a new route ``get '/users'`` that will display a list of all of the users in your database
    4. Next, create a another route `` get '/users/:id`` that will display the information for only one user. For example - by typing ``localhost:4567/users/3`` in your address bar, you should be redirected to a page that only displays the information for the user in your database that has an id of 3.
    5. On the detail page (from the step above) - display the name and email of the user. Also, display a list of the post titles they have

    Hint: We went through these steps using the sinatra_todo application, so reference that application to guide your through this assignement


    2. ***VERY IMPORTANT:*** If you haven't already done so; please ensure that your laptop is correctly set up for Rails development by following the setup instructions found on [installrails.com](http://installrails.com/). If this is not completed before next class, you ***will*** run into issues and you may fall behind.

  3. kareemgrant created this gist Jun 6, 2015.
    19 changes: 19 additions & 0 deletions adding_data_to_your_views_sinatra.markdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    ## Basic ActiveRecord Sinatra

    ### Goals

    1. Understand how to create and access a database with ActiveRecord

    2. See how this database will be used and accessed from your Sinatra application

    ### Assignment

    1. Create a new sinatra app called ``sinatra_blog`` and add a database to the app using the steps specified in class. Add a ``users`` table to the database with the following fields: email and full_name. Then create a ``User`` model in the app that can be used to create (read, update or delete) new user records using activerecord. The assignment will be considered complete when you are able to succesfully create new users in IRB (as specified in class).

    2. ***VERY IMPORTANT:*** If you haven't already done so; please ensure that your laptop is correctly set up for Rails development by following the setup instructions found on [installrails.com](http://installrails.com/). If this is not completed before next class, you ***will*** run into issues and you may fall behind.


    ### Recommended Activity

    Read up on HTML forms:
    [http://www.w3schools.com/html/html_forms.asp](http://www.w3schools.com/html/html_forms.asp)