2012-05-24 68 views
0

所以基本上在我的部分我有下面的代碼行變量傳遞到軌道部分

... 
<%= " active" if current_user."#{prop_row}" == "repeat-x" %> 
... 

於是,我在下面的變量「PROP_ID」通過,「prop_row」使用:

<%= render :partial => "users/image_props/repeat", :prop_id => "mbr", :prop_row => "main_background_repeat" %> 

我得到的錯誤

/Users/codyjames408/rails/moz/app/views/users/image_props/_repeat.html.erb:4: syntax error, unexpected tSTRING_BEG 
...= (" active" if current_user."#{prop_row}" == "repeat-x");... 
...  

        ^

我認爲這些錯誤,因爲它附加一個字符串,而不是該行的方法。但我正在拉我的頭髮,試圖找出如何解決這個問題。

我很想把它變成一個大幫手的方法或者什麼!我只是不知道如何...

回答

2

如果prop_row是一個字符串,包含屬性的名稱,你UCAN做到這一點:

<%= " active" if current_user.attributes[prop_row] == "repeat-x" %> 

或者使用:

<%= " active" if current_user.send(prop_row.to_sym) == "repeat-x" %> 
+0

剛我需要感謝! –