2016-01-31 50 views
0

我有我的形象標籤的語法錯誤在我的Ruby on Rails應用程序:圖片沒有出現在意見

<%= image_tag('smiley.png'), :class =>"img-responsive", :style => "height:90%; width:60%;" %> 

它說:「意外的關鍵字」和「預期結束輸入」。有人可以告訴我這個語法有什麼問題嗎?

+2

當問一個錯誤,把確切的錯誤信息到你的問題。不要解釋它,也不要刪除錯誤的行號等細節。閱讀「[mcve]」。 –

+0

如果您在任何課程中設置圖片尺寸,最好也是。 – monteirobrena

回答

1

documentation

<%= image_tag('smiley.png', class: 'img-responsive', style: 'height:90%; width:60%;') %> 

-

豐富派克編輯...

這是編程的基本argument assignment

當您調用函數時,您可以將數據傳遞給它,如參數。這些參數表示local variables,您可以在函數/子例程中使用它們。

由於image_tag是一個接受參數的函數,你的問題是你關閉了括號,阻止了參數的傳遞。

你只需要包含函數的括號內的class & style選擇他們作爲有效的參數傳遞。您也可以從知道Ruby doesn't need brackets受益:

<%= image_tag "smiley.png", class: "img-responsive", style: "height: 90%; width: 60%;" %> 
+1

感謝編輯@RichPeck。乾杯:) – Vucko