<commit_before># Lab 2

**Table of Contents**

- [Prereq](##prereq)
- [Install](##install)
- [Create a New App](##create-a-new-app)
- [Push Code to Github](##push-code-to-github)

# Building an App from the Ground Up

---
## Prereq


```
$ vagrant ssh
```

## Install

Install and run a local database:

```
$ sudo yum -y install mariadb mariadb-server mariadb-devel
$ sudo systemctl start mariadb.service
```

Install dependencies:

```
$ sudo yum -y install links
$ sudo yum -y install nodejs
```

Install Rails:

```
$ gem install rails
```

## Create a New App

```
$ rails new --skip-turbolinks --skip-spring \
            --skip-test-unit -d mysql \
            myapp
```

Create the database and schema.

```
$ cd myapp
$ bundle exec rake db:create
$ bundle exec rake db:migrate
```

Run our new app. Note: setup port forwarding first.

```
$ bundle exec rails server -b 0.0.0.0
```

Go to `http://localhost:3000/` on your browser.

Use ctrl-c to quit rails. Now add scaffolding. 

```
$ bundle exec rails generate scaffold Bootcamp name:string description:text dates:string
$ bundle exec rake db:migrate
```

Add a default route to `config/routes.rb`

```
root 'bootcamps#index'
```

Run the app.

```
$ bundle exec rails server -b 0.0.0.0
```

Go to `http://localhost:3000/` on your browser.

Now edit `app/views/bootcamps/show.html.erb` and make the description field a `raw` field. It should look like so:

```
...
<p>
  <strong>Description:</strong>
  <%=raw @bootcamp.description %>
</p>
...
```

Now run the app, and create a new bootcamp entry. What can you do in the description field? What are the security implications of using the `raw` method.



## Push Code to Github<commit_msg>Added section for student challenge<commit_after># Lab 2

**Table of Contents**

- [Prereq](##prereq)
- [Install](##install)
- [Create a New App](##create-a-new-app)
- [Push Code to Github](##push-code-to-github)

# Building an App from the Ground Up

---
## Prereq


```
$ vagrant ssh
```

## Install

Install and run a local database:

```
$ sudo yum -y install mariadb mariadb-server mariadb-devel
$ sudo systemctl start mariadb.service
```

Install dependencies:

```
$ sudo yum -y install links
$ sudo yum -y install nodejs
```

Install Rails:

```
$ gem install rails
```

## Create a New App

```
$ rails new --skip-turbolinks --skip-spring \
            --skip-test-unit -d mysql \
            myapp
```

Create the database and schema.

```
$ cd myapp
$ bundle exec rake db:create
$ bundle exec rake db:migrate
```

Run our new app. Note: setup port forwarding first.

```
$ bundle exec rails server -b 0.0.0.0
```

Go to `http://localhost:3000/` on your browser.

Use ctrl-c to quit rails. Now add scaffolding. 

```
$ bundle exec rails generate scaffold Bootcamp name:string description:text dates:string
$ bundle exec rake db:migrate
```

Add a default route to `config/routes.rb`

```
root 'bootcamps#index'
```

Run the app.

```
$ bundle exec rails server -b 0.0.0.0
```

Go to `http://localhost:3000/` on your browser.

Now edit `app/views/bootcamps/show.html.erb` and make the description field a `raw` field. It should look like so:

```
...
<p>
  <strong>Description:</strong>
  <%=raw @bootcamp.description %>
</p>
...
```

Now run the app, and create a new bootcamp entry. What can you do in the description field? What are the security implications of using the `raw` method.

## Add Your Own Functionality

Do one of the following:

1. Capability to upload and display an image when creating/showing a bootcamp entry
2. Integrate Devise to authenticate users
3. Implement access controls for the bootcamp model

**Challenge:** do all 3.

**Resources:**

* Rails Form Helpers: [http://guides.rubyonrails.org/form_helpers.html](http://guides.rubyonrails.org/form_helpers.html)
* Devise: [https://github.com/plataformatec/devise](https://github.com/plataformatec/devise)

## Push Code to Github
{'fraction_non_alphanumeric': 0.13793103448275862, 'fraction_numerical': 0.009706257982120051, 'mean_word_length': 3.5011494252873563, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4851305', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1296, 'n_words': 462}