2013-02-12 56 views
0

我有一個link_to image_tag,點擊時應彈出一個模式來顯示幫助屏幕。按鈕的代碼是:Rails 3中的動態按鈕3

<%= link_to image_tag('help_sm.png'), '#', :id =>"btnShowHelp_"{current_step} %>

其中{current_step}是步驟的名稱,用戶是對應於他們所訪問的幫助屏幕。

我得到一個SyntaxError輸出current_step

有人可以幫助正確的語法嗎?

回答

1

插在紅寶石的字符串看起來是這樣的:"#{var}",所以你需要這樣做:

<%= link_to image_tag('help_sm.png'), '#', :id =>"btnShowHelp_#{current_step}" %> 

請注意,你必須使用字符串插值雙引號("),如果使用單引號( '),它不會內插。

+0

修復了問題,但導致了另一個問題。現在我有一個NameError與此: '<%= @ project.current_step.capitalize%>     <%= link_to image_tag('help_sm.png'),'#',:id =>「btnShowHelp _#{current_step }「%>' 'current_step'在第一部分中工作,但不在第二部分。想法? – Matteo 2013-02-12 04:12:46

+1

修復了NameError - '...#{@ project.current_step}「' – Matteo 2013-02-12 04:21:44

+0

很高興您的工作,做得好:) – Andrew 2013-02-13 16:22:35