Rails - Miscellaneous

rails

What is WEBrick?

WEBrick is web server distributed with Ruby by default.

In general, does Rails require you to restart WEBrick?

No. Rails does not generally require you to restart the server; changes you make in files will be automatically picked up by the server.

What is this execjs error stuff and how can we get around it?

Compiling CoffeeScript to JavaScript requires a JavaScript runtime and the absence of a runtime will give you an execjs error. Usually Mac OS X and Windows come with a JavaScript runtime installed. Rails adds the therubyracer gem to the generated Gemfile in a commented line for new apps and you can uncomment if you need it. therubyrhino is the recommended runtime for JRuby users and is added by default to the Gemfile in apps generated under JRuby. You can investigate about all the supported runtimes at ExecJS.

How to declare / define a resource?

Rails provides a resources method which can be used to declare a REST resource.

How to display a list of routes?

rake routes

What is the purpose of the 'app' folder?

The 'app' folder contains the controllers, models, views, helpers, mailers and assets for your application.

After you use the Rails application builder / generator to create the 'blog' application. It creates the 'blog' folder, and inside this 'blog' folder, it also creates a number of files and folders. The 'app' folder contains the controllers, models, views, helpers, mailers and assets for your application.

What is the purpose of the 'bin' folder?

It contains the rails script that starts your app and can contain other scripts you use to deploy or run your application.

What is the purpose of the 'config' folder?

It configure your application's routes, database, and more. This is covered in more detail in Configuring Rails Applications.

What is the purpose of the 'config.ru' file?

Rack configuration for Rack based servers used to start the application.

What is the purpose of the 'db' folder?

It contains your current database schema, as well as the database migrations.

What is the purpose of the Gemfile and Gemfile.lock file?

These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the Bundler gem. For more information about Bundler, see the Bundler website.

What is the purpose of the 'lib' directory?

It contains extended modules for your application.

What is the purpose of the 'log' folder?

It contains your application log files.

What is the purpose of the 'public' folder?

It is the only folder seen by the world as-is. It contains static files and compiled assets.

What is the purpose of the Rakefile file?

This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing Rakefile, you should add your own tasks by adding files to the lib/tasks directory of your application.

What is the purpose of the README.rdoc file?

This is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on.

What is the purpose of the 'test' folder?

It contains unit tests, fixtures, and other test apparatus. These are covered in Testing Rails Applications.

What is the purpose of the 'tmp' folder?

It contains temporary files (like cache, pid, and session files).

What is the purpose of the 'vendor' folder?

It is a place for all third-party code. In a typical Rails application this includes vendored gems.

How to declare / define a resource?

Rails provides a resources method which can be used to declare a REST resource.

How to display a list of routes?

rake routes

What are the rules for defining a model in Rails?

Models in Rails use a singular name, and their corresponding database tables use a plural name.

How can we see all the arguments that the Rails application builder / generator accept?

rails new -h
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License