|
| 1 | +# Contribution |
| 2 | +So you're interested in contributing to PureChart? Excellent - we're grateful for the help! |
| 3 | + |
| 4 | +## Create Example Project |
| 5 | +We recommend creating a simple project to test your work. |
| 6 | + |
| 7 | +> Note that we're using Ruby `3.0.0` and Rails `7.0.8`. If you encounter unexpected errors, try using these versions instead. |
| 8 | +
|
| 9 | +First, choose the directory where you will be working and run `rails new metrics` to generate a new Ruby on Rails project. We've called the application "metrics" because one might use our charts for some kind of analytics application, but you may choose whatever name you'd like. |
| 10 | + |
| 11 | +## Clone PureChart |
| 12 | +Next, clone the PureChart gem from GitHub in the same directory (not in `/metrics`) as so - |
| 13 | + |
| 14 | +```sh |
| 15 | +git clone https://github.com/PureChart/purechart.git |
| 16 | +``` |
| 17 | + |
| 18 | +## Add PureChart to Project |
| 19 | +Let's add the local version of PureChart to the metrics application. Open `metrics/Gemfile` and add the following line somewhere in the file. |
| 20 | + |
| 21 | +#### metrics/Gemfile |
| 22 | +```ruby |
| 23 | +gem "purechart", path: "../purechart" |
| 24 | +``` |
| 25 | + |
| 26 | +Move to the `metrics` directory in your terminal and run `bundle install` to install the gem. Finally, run `bin/rails server` and you're ready to go! If you visit `http://127.0.0.1:3001` in your web browser, you'll see the following webpage - |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +## Create a Chart |
| 31 | +Now that we have a working test project, let's add a new page called "dashboard." Ruby on Rails provides many nice generator commands, and we'll use one of them right now. But first, open `metrics/config/routes.rb`. It should look like this - |
| 32 | + |
| 33 | +#### metrics/config/routes.rb |
| 34 | +```ruby |
| 35 | +Rails.application.routes.draw do |
| 36 | + # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html |
| 37 | + |
| 38 | + # Defines the root path route ("/") |
| 39 | + # root "articles#index" |
| 40 | +end |
| 41 | +``` |
| 42 | + |
| 43 | +This contains all the routes our application will handle. Add a new route that will point to our dashboard page - |
| 44 | + |
| 45 | +#### metrics/config/routes.rb |
| 46 | +```ruby |
| 47 | +Rails.application.routes.draw do |
| 48 | + get "/dashboard", to: "dashboard#index" |
| 49 | + ... |
| 50 | +end |
| 51 | +``` |
| 52 | + |
| 53 | +Finally, run `bin/rails generate controller Articles index --skip-routes` to create a **controller** for the dashboard. Ruby on Rails uses the MVC model, which stands for **M**odel **V**iew **C**ontroller. Long story short, the controller decides what data to collect and what views to render based on a user request. The `--skip-routes` flag at the end is necessary because we've already added the route manually. |
| 54 | + |
| 55 | +> [RAILSG](https://railsg.xyz/) is an awesome website that helps you build Ruby on Rails generator commands. Definitely give it a whirl at some point. |
| 56 | +
|
| 57 | +This will create a few new files. We're most interested in... |
| 58 | + |
| 59 | +- The controller (`app/controllers/dashboard_controller.rb`), and |
| 60 | +- The view (`app/views/dashboard/index.htmk.erb`). |
0 commit comments