Java Magazine, July/August 2016
ORACLE COM JAVAMAGAZINE JULY AUGUST 2016 64 jvm languages create vendor assets stylesheets create vendor assets stylesheets keep run bundle install Fetching gem metadata from https rubygems org Fetching version metadata from https rubygems org Fetching dependency metadata from https rubygems org Resolving dependencies Using i18n 070 Using json 183 Installing minitest 590 Installing sass rails 504 Installing turbolinks 253 Bundle complete 11 Gemfile dependencies 54 gems now installed Use bundle show gemname to see where a bundled gem is installed Due to width constraints some lines in this output and in other output shown in this article have been truncated folded or had unnecessary data removed Ed Now the magic of Rails starts to kick in By using the rails new command I get a fully functional bare bones application complete with a welcome page a conventionbased filesystem layout and a basic database configuration using sqlite3 you can specify a different database with the d flag Rails constructs the application and then runs the bundle command Bundler is a gem based dependency management tool for applications Rails builds a Gemfile containing a list of all libraries required for the app and Bundler makes sure theyre installed At this point I can start up the Rails application even though I havent written any logic cd my_ app rails server Booting WEBrick Rails 426 application starting in development on http localhost 3000 Run rails server h for more startup options Ctrl C to shutdown server 2016 06 INFO WEBrick 131 2016 06 INFO ruby 230 2016 06 06 java 2016 06 INFO WEBrick HTTPServer start pid 37393 port 3000 Lets quickly scaffold some basic functionality for our application In Rails scaffolding is code generated at development time that provides a rough structure for your application You can tell Rails to generate models views controllers tests and more The following example generates the basic code for CRUD operations against a post with a title and a body rails generate scaffold post title body text invoke active_ record create db migrate 20160606083900_ create_ posts rb create app models post rb invoke test_ unit create test models post_ test rb create test fixtures posts yml invoke resource_ route route resources posts invoke scaffold_ controller create app controllers posts_ controller rb invoke erb create app views posts create app views posts index html erb create app views posts edit html erb create app views posts show html erb create app views posts new html erb create app views posts_ form html erb
You must have JavaScript enabled to view digital editions.