2011-05-01 63 views
1

我正在研究Rails應用程序並使用HAML來實現視圖。我想用「滑動門」技術來創建漂亮的按鈕,這意味着我需要得到HAML產生類似於下面的HTML的東西:HAML中的靈活圖像按鈕

<a href="#" class="button"><span class="button">Button text</span></a> 

我一直無法弄清楚如何通過HAML參考或Google進行。你能幫忙嗎?提前謝謝了。

編輯:爲了澄清,我需要使用link_to助手,因爲我鏈接到資源。當我嘗試塊傳遞給方法,我得到一個錯誤:undefined method 'stringify keys'

回答

4

嘗試

= link_to invitation_path(invitation), :method=>:put, :class=>"button" do 
    %span(class="button") 
    Accept 
+0

我仍然遇到上述錯誤。 – Lyudmil 2011-05-01 04:18:42

+0

你能澄清你想輸出的html嗎?我嘗試了我放在我的答案中的代碼,並且它與您的問題中的html完全相同。有沒有可能導致錯誤的信息? – robzolkos 2011-05-01 04:20:12

+0

當然。我有一個邀請模式。用戶可以接受或拒絕邀請。在視圖中我有:link_to「Accept」,invitation,:method =>:put,:class =>'button accept'。我想要在鏈接中呈現一個跨度,就像我在問題中所描述的那樣。如果我添加一個塊,我會得到上面提到的錯誤。看起來很有可能你的建議完美,但在處理資源時失敗。 – Lyudmil 2011-05-01 04:23:12

1

這應該是簡單:

%a(href="#" class="button") 
    %span(class="button") Button text 

或者,如果你特別希望在同一行不,你可以做任何空白:

%a(href="#" class="button")< 
    %span(class="button") Button text 
+0

不幸的是我需要使用的link_to助手。對不起,我沒有在問題中說清楚。我會適當地編輯它。 – Lyudmil 2011-05-01 03:59:21