ruby on rails继续

  $ rails generate controller FooBars baz quux

  $ 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")








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值