2011-06-19 29 views
7

Ruby on Rails'e çok yeni ve Haml'a daha yeni geliyorum, 2 saat önce kullanmaya başladım. Bu yüzden bir Ruby on Rails eğiticisini takip ediyorum ve Haml'ı görüşlere ayırmaya karar verdim, ama bu şeyleri görüntülemenin doğru yolu olup olmadığından emin değilim (biraz garip hissettiriyor). Birisi beni aydınlatır mı?Haml kullanarak metni görüntülemek/birleştirmek için doğru yol bu mu?

:ruby 
    first_link = link_to 'Ruby on Rails Tutorial','http://railstutorial.org' 
    second_link = link_to 'Ruby on Rails', 'http://rubyonrails.org' 

%h1= "About Us" 
%p 
    = first_link 
    &= 'is a project to make a book and screencasts to teach web development with' 
    &= second_link 
    &= '. This is the sample application for the tutorial.' 

cevap

11

Metnin bloğu içinde yakut kodunu kaydırmak için #{} kullanabilir ve sadece (senin %h1 gibi) metin isterseniz sizi: :)

%h1= "About Us" 
%p 
    =link_to 'Ruby on Rails Tutorial','http://railstutorial.org' 
    &= 'is a project to make a book and screencasts to teach web development with' 
    &= link_to 'Ruby on Rails', 'http://rubyonrails.org' 
    &= '. This is the sample application for the tutorial.' 

Bu çok denedim ='u kullanmanıza gerek yoktur.

%h1 About Us 
%p 
    #{link_to 'Ruby on Rails Tutorial','http://railstutorial.org'} is a project to make a book and screencasts to teach web development with #{link_to 'Ruby on Rails', 'http://rubyonrails.org'}. This is the sample application for the tutorial. 

Eğer onun daha kolay editörü işlemek için böylece her biri aynı miktarda hattı girinti ve Ruby fonksiyonunun ortasında bölmek yok emin olun, çizgi kırmak isterseniz:

%h1 About Us 
%p 
    #{link_to 'Ruby on Rails Tutorial','http://railstutorial.org'} is a project to make a 
    book and screencasts to teach web development with #{link_to 'Ruby on Rails', 'http://rubyonrails.org'}. 
    This is the sample application for the tutorial. 
+0

Mükemmel cevap, çok teşekkür ederim. :) –

İlgili konular