精讀railsyardcms(1)

(1)除了HTML內容之外,經常也有人在代碼中加入註釋:

<!-- This is a comment -->
其中This is a comment會被隱藏,註解中的就是隱藏的意思,僅僅起到說明代碼含義或者隱藏部分代碼的作用。

(2)HTML CLASS 引用庫裏面聲明的樣式

<h1 class="intro">Header 1</h1>

(3)html  rel 屬性規定當前文檔與被鏈接文檔之間的關係。
   實例
   在下面的例子中,rel 屬性指示被鏈接的文檔是一個樣式表:
   <head>
   <link rel="stylesheet" type="text/css" href="theme.css" />
   </head>

(4)ruby: current_theme_stylesheet_path

def current_theme_stylesheet_path(asset)
      base_theme_stylesheet_path(:theme => self.theme_name, :asset => "#{asset}.css")
    end

   def themes_dir
      @themes_dir ||= ":root/themes"
    end

然後我在railsyardcms/themes/rough/stylesheets下面找到了衆多的.css文件

(5)ruby: render:partial

        <%= render :partial => "account" %>

      默認本地有個變量@account, 傳遞過去,render到的partial(_account.erb)有個變量account .

   <%= render :partial => "account", :locals => { :account => @buyer } %>  

   locals傳遞一組hash參數hash 值是本地的變量,hash的key是partial裏的變量。傳遞本地變量@buyer到_account.erb裏叫account的參數。//這個_account.html.erb在partials目錄下會有的.

(6)html meta
   <meta> 元素可提供有關頁面的元信息(meta-information),比如針對搜索引擎和更新頻度的描述和關鍵詞。
   <meta> 標籤位於文檔的頭部,不包含任何內容。<meta> 標籤的屬性定義了與文檔相關聯的名稱/值對。

     註釋:<meta> 標籤永遠位於 head 元素內部。

     註釋:元數據總是以名稱/值的形式被成對傳遞的。

(7)sytlesheet_link_tag

      <%= stylesheet_link_tag "books.css" %>                              使得視圖調用模板/public/stylesheets/下的books.css

<%= stylesheet_link_tag "style" %>        ==                        <link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />

<%= stylesheet_link_tag "style.css" %>    ==                        <link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />
<%= stylesheet_link_tag "style", :media => "all" %>      ==         <link href="/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />

<%= stylesheet_link_tag "style", :media => "print" %>     ==         <link href="/stylesheets/style.css" media="print" rel="stylesheet" type="text/css" />
<%= stylesheet_link_tag "random.styles", "/css/stylish" %>    ==
<link href="/stylesheets/random.styles" media="screen" rel="stylesheet" type="text/css" />
<link href="/css/stylish.css" media="screen" rel="stylesheet" type="text/css" />
<%= stylesheet_link_tag :all %>                               ==
  <link href="/stylesheets/style1.css"  media="screen" rel="stylesheet" type="text/css" />
  <link href="/stylesheets/styleB.css"  media="screen" rel="stylesheet" type="text/css" />
  <link href="/stylesheets/styleX2.css" media="screen" rel="stylesheet" type="text/css" />

(8)ruby:yield

       大學裏常常發生佔位置的現象:頭天晚上拿一本書放在課座上,表示位置已經被佔了;第二天才來到這個座位上,翻開書正式上課.在這個現象中,“書本”充當了“佔位符”的作用。 在Ruby語言中,yield是佔位符:先在前面的某部分代碼中用yield把位置佔着,然後纔在後面的某個代碼塊(block)裏真正實現它,從而完成對號入座的過程.

#定義find  
def find(dir)  
    Dir.entries(dir).each {|f| yield f} #獲得dir目錄下的文件名列表;對每個文件名,用yield來處理(至於怎麼處理,還不知道,佔個位置先^_^)end  
#使用find  
find(".") do |f| #block開始  
  puts f  #用輸出文件名這個語句,真正實現了yield的處理(也可以用任何其他語句)  
end #block結束 
         由此可見,yield屬於定義層,屬於宣告層,也就是在心裏說一句:"這個位置不錯,我先用書本佔了再說!";而block屬於使用層,實現層,也就是最終你坐在了你先前佔的位置上,從而真正的實現了對號入座的過程. 

(9)<%= javascript_include_tag :defaults %>
     <%= csrf_meta_tags %>  則相應的html代碼與下面類似:
      <meta name="csrf-param" content="authenticity_token"/><meta name="csrf-token" content="WO8dau2vScU/ad3JKLh2jRdSm7N8QEdNfX3ggGawxOE="/>
這段代碼主要解決的就是csrf的問題。這兩行代碼的csrf-token數值是由當前瀏覽器與服務器之間建立的連接而生成的,與sid有關。ujs頁面的ajax post都會自動附帶
authenticity_token的字段。這樣可以有效避免一般的跨站的腳本惡意訪問~~








發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章