Dozerslist Routes

Report 6 Downloads 85 Views
 

Routes DIRECTIONS:​Follow along as you begin learning the basics of Ruby on Rails, a powerful framework for creating dynamic, data-driven websites. ❏

Login to Cloud9

● Go to ​ https://c9.io/web/login



Open Workspace

● Click OPEN on your ​ ruby-on-rails​ workspace tile



Make Sure Your Application is Running

● Change directory to ​ dozerslist​ ,​​ your application’s directory: $​ cd dozerslist

● Launch the Rails server: ​ $​ rails s -b $IP -p $PORT ❏

View the Application’s Current Routes

● In your browser, go to your application’s URL ● Add ​ /rails/info​ to the end: http://ruby-on-rails-bobleeswagger.c9.io/​ rails/info

As you can see, our application currently has no routes

Page 1 of 4



Add a Resource Route

● Double-click on the ​ routes.rb​ file in the filesystem navigator; (this will open the file in the text editor) ● Immediately under the ​ do​ l​ ine in the file, insert the following: resources :items



Save the File

● FILE Menu > Save



View the Application’s Current Routes

● Refresh your application’s URL in the browser: http://ruby-on-rails-bobleeswagger.c9.io/​ rails/info

As you can see, our application now has routes ❏

Add Controller for Items Routes

● Create a new controller, for ​ items​ routes, by issuing the following command from the ​ dozerslist​ directory: $​ rails generate controller items

The output should resemble the following: create app/controllers/items_controller.rb invoke erb

Page 2 of 4

create invoke create invoke invoke create invoke create



app/views/items helper app/helpers/items_helper.rb assets coffee app/assets/javascripts/items.coffee scss app/assets/stylesheets/items.scss

Test Route

● Request ​ /items​ from the application:

We now have a controller for the items users will post to Dozerslist, but there are no actions defined to respond to users’ requests. In this case, there is no ​ index​ action to respond to the request made for the / ​items​ resource. ❏

Look Closer at the Controller

● In the filesystem navigator, double-click on the app/controllers/items_controller.rb​ file class​​ ItemsController​​ Save



Test the Route Again

● If successful, you should see the following:



Save and Close the Project

● FILE Menu > Save All ● Cloud9 > Quit Cloud9



​ WELCOME TO DOZERSLIST​

Page 4 of 4