所以我的問題是以一種更好更簡單的方式展示模型。在Rails 4中顯示相應text_field_tag值的優雅方式
那麼目前的工作?
在我的瀏覽器能正常工作:
<%= text_field_tag(:first_name, (current_user.present? ? current_user : '').first_name.present? ? current_user.first_name : '') %>
然而,這是太長,真的很難維持,尤其是當我有幾個領域。
因此,爲了避免我在我的控制器
def user_vals(value)
if(current_user.present?)
current_user.value.present? ? current_user.value : ''
end
return ''
end
使這個在這個控制器我可以叫user_vals(:first_name)
,但得到undefined method
value'`錯誤。此外,我不能只打電話
<%= text_field_tag(:first_name, @user_vals(:first_name)) %>
由於我收到一些括號的語法錯誤,但這不是真正的問題。
所以我的最終目標是有這樣的事情:
<%= text_field_tag(:first_name, @user_vals(:first_name)) %>
而不是第一個代碼,我上面給出。我怎樣才能做到這一點?
''''profile_vals'''的意圖是什麼? – Carl 2014-08-30 13:36:40
我的壞我的意思是用戶 – 2014-08-30 13:44:08