Rails学习笔记2.1、2.2

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 %>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值