Seven Seas Module Two Week One Review

Seven seas...
Seven restful routes...
Seven days of studying web frameworks...
And now it's time to review with a Sinatra to Rails challenge!

What You Have Now

You've been provided with the Sinatra Seven Seas application. It has full CRUD actions for the resource 'sea' and an MVC framework. Take a few minutes to look through the app and familiarize yourself with the code. Then, fire up shotgun in terminal and see how it looks!

Notice all the fancy styling? That comes from a popular front-end styling framework called Bootstrap. If you look in 'app/views/layout.erb', you'll see the Bootstrap styling linked. All of the css classes used in the application come from Bootstrap.

Don't worry if the styling seems a bit magical right now; your focus will be mainly on the MVC structure.

Goal

Your job is to recreate the Seven Seas application in Rails. To a user, the Sinatra and Rails apps should be indistinguishable.

Feel free to copy/paste where applicable from Sinatra to Rails. While copy-pasta is usually discouraged in Learn labs, the goal of this lesson is to become aware of the similarities and differences between Rails and Sinatra applications.

Caveats and Tips

  • In order to give your Rails Seven Seas Bootstrap styling, simply copy the two bootstrap stylesheet lines from the Sinatra 'app/views/layout.erb' head, and move them to 'Rails-Seven-Seas/app/views/layouts/application.html.erb'.
  • We've built Rails new and edit forms for you, since Rails forms have some built-in security features with conventions we have to follow. Once you get the form views rendered in your browser, inspect the HTML to see what is being generated by Rails's form_for.
  • Use rails s to start a server and rails c to enter a console. Confirm your assumptions early and often!

Instructions

  • Where do we start with any Sinatra or Rails application? bundle install, of course! Next, run rails s and go to http://localhost:3000/, to see a welcome page. Woohoo, you're on the Rails!
  • You'll need a database populated with the seven lovely seas from the Sinatra application. Think about what code can be recycled from the Sinatra app's db folder.
  • In Rails, routes are separated from controllers. Because Rails is awesome, the routes.rb file contains a link to the Rails documentation for routes. Since you're building full CRUD for a sea, add all seven RESTful routes to this file.
  • Now, your job is to work out the MVC--Model, View, Controller--part of this app. When making your model, controller, and views, remember that naming conventions are very important in Rails!
  • You will have to do some research to implement the delete functionality. Check out how the delete is built in Sinatra and think about why the same approach won't work in Rails.

Stuck?

  • Run rake -T to see your rake tasks
  • Run rails c to check and update your data
  • Run rails s and test your code in the browser
  • Use byebug (it's just like pry) to check your controller actions
  • Check the (excellent) Rails documentation or Google the error

Bonus

Uh oh, the Rails forms have no styling! Check the Rails documentation to see how to add css styling to Rails forms.