rails new demo
The command has created a directory name demo. Pop down into that directory, and list its contents. You should see a bunch of files and subdirectories.
rake about
Examine the installation. If you see bunch of messages concerning already initialized constants or a possible conflict with an extension, consider deleting the demo directory, creating a separate RVM gemset, and starting over. If that doesn't work, use bundle exec to run rake commands.
Once you get rake about working, you have everything you need to start a standalone web server that can run our newly created Rails application.
rails server webrick
If another web server is installed on your system (and Rails can find it), the rails server command may user it in preference to WEBrick. You can force Rails to user WEBrick by providing an option to the rails command.
Rails is a Model-View-Controller framework. Rails accepts incoming request from a browser, decodes the request to find a controller, and calls an action method in that controller. The controller then invokes a particular view to display the results to the user. The good news is that takes care of most of the internal plumbing that links all these actions.
rails generate controller Say hello goodbye
To create a controller called say, passing in the name of the controller we want to create and the names of the actions we intend for this controller to support.
Look at demo/app/controllers/say_controller.rb :
class SayController < ApplicationController
def hello
end
def goodbye
end
end<span style="color:#33ffff;">
</span>
For now , the code does nothing ---- wo simply have empty action methods named hello() and goodbye().
A Rails application appears to its users to be associated with a URL. When you point your browser at that URL, you are talking to the application code, which generates a response to you.
When we ran the script to create the new controller,the command added several files and a new directory to our application. That directory contains the template files for the controller's views. In our case, we created a controller named say, so the views will be in the directory app/view/say.v
It's now <%= Time.now %>
@time = Time.now
It's now <%= @time %>