ROR(三)

def self.find_products_for_sale
    find(:all, :order => "title")            
end


P66
#這裏使用了Rails提供的find()方法,:all參數代表我們希望取出符合指定條件的所有記錄。
通過詢問用戶,我們確定了關於“如何對列表進行排序”,先按照貨品名稱排序,看看效果。於是:order=>”title”


<% hidden_div_if(@cart.items.empty?, :id => "cart") do%>
    <%= render(:partial => "cart", :object => @cart) %>
<% end %>


P98
#書上少了do和end,第一行多了“=”,加上=會作爲to_s方法來調用,同樣問題在P92頁也出現
#中間render應該是作爲block參數傳進hidden_div_if方法

content_tag(:div, attributes, &block)
第一個參數代表標籤,中間是標籤的屬性,寫成hash的形式,源碼文檔如下
# Returns an HTML block tag of type +name+ surrounding the +content+. Add
       # HTML attributes by passing an attributes hash to +options+.
       # Instead of passing the content as an argument, you can also use a block
       # in which case, you pass your +options+ as the second parameter.
       # Set escape to false to disable attribute value escaping.
       #
       # ==== Options
       # The +options+ hash is used with attributes with no value like (<tt>disabled</tt> and
       # <tt>readonly</tt>), which you can give a value of true in the +options+ hash. You can use
       # symbols or strings for the attribute names.
       #
       # ==== Examples
       #   content_tag(:p, "Hello world!")
       #    # => <p>Hello world!</p>
       #   content_tag(:div, content_tag(:p, "Hello world!"), :class => "strong")
       #    # => <div class="strong"><p>Hello world!</p></div>
       #   content_tag("select", options, :multiple => true)
       #    # => <select multiple="multiple">...options...</select>
       #
       #   <%= content_tag :div, :class => "strong" do -%>
       #     Hello world!
       #   <% end -%>
       #    # => <div class="strong">Hello world!</div>
       
       


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