$ rails destroy controller FooBars baz quux
如果你已经建立了复杂的controller的框架,router中已经设好了怎么办,没关系,上面两个语句完全是相反的,用吧,完全取消哦,亲!
rails generate model Foo bar:string baz:integer
rails destroy model Foo
rake db:migrate rake db:rollback rake db:migrate VERSION=0 这个用来迁徙数据库到你想要的版本,
rails generate controller StaticPages home help
get "static_pages/home"
maps requests for the URI /static_pages/home to the home action in the StaticPages controller.
The hypertext transfer protocol (HTTP) defines four basic operations, corresponding to the four verbs get, post, put, and delete.GET is the most common HTTP operation, used for reading data on the web; it just means “get a page”, and every time you visit a site like google.com or wikipedia.org your browser is submitting a GET request. POST is the next most common operation; it is the request sent by your browser when you submit a form. In Rails applications, POST requests are typically used for creating things. for example, the POST request sent when you submit a registration form creates a new user on the remote site. //get 当你访问页面的时候用到,Post当你创造了一些东西,比如说注册之类的时候用到。The other two verbs, PUT and DELETE, are designed for updating and destroying things on the remote server.
无需浏览器的代码测试:
rails generate integration_test static_pages 生成测试代码 在spec/request下面static_pages_spec.rb
最后通过bundle exec rspec spec/requests/static_pages_spec.rb 来测试结果
<% provide(:title, 'Home') %>indicates using <% ... %> that Rails should call the provide function and associate the string ’Home’ with the label :
title.14 Then, in the title, we use the closely related notation <%= ... %> to insert the title into the template using Ruby’s yield function:
<title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title>
如何在erb文件里嵌入ruby
(The distinction between the two types of embedded Ruby is that <% ... %> executes the code inside, while <%= ... %> executes it and inserts the result into the template.) 没有等于号的只是执行一下代码,有等于号的是执行完了还要贴到原来的位置。
<%= csrf_meta_tags %> 这个是为了 prevents cross-site request forgery (CSRF), a type of malicious web attack.
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
home.html.erb
<% provide(:title, 'Foo') %>
<!DOCTYPE html>
<html>
<body>
Contents
</body>
</html>
let(:base_title) { "Ruby on Rails Tutorial Sample App" } page.should have_selector('title', :text => "#{base_title} | Home")