0
我對如何在Rails中編寫實例變量感到困惑。如何編寫實例變量的代碼困惑
Posted by: <%= link_to(@item.user.username, store_path(@item.user)) %>
Price: <%= number_to_currency @item.price %>
VS
Subject: <%= subject_name @item %>
我只是好奇,是什麼(我)SUBJECT_NAME @item及(ii)@ item.price之間的區別?
它不應該是@ item.subject_name嗎?
'subject_name'會在你的幫手中定義.. – Nithin
'subject_name'可能是[helper method](http://codefol.io/posts/Where-Do-I-Put-My-Code)它是就像其他任何可以在'view'中調用的方法一樣。在'@ item.price'中,'@ item'是'Item'類的實例對象,'price'是該模型的屬性。這就是爲什麼它可以用'dot'符號調用 – kiddorails
只有** subject_name **是Item Item中的一個實例方法,或者它是'items'表中的一個字段,纔可以調用**@item.subject_name**。在這裏,它可能是一個輔助方法。 – Abhi