1
我不知道這是可能的,但如果用戶創建了一個名爲使命陳述的估值表單標籤:如何根據標籤調用text_field?
<%= f.text_field :name %>
<%= f.text_field :tag_list, valuation: @valuation.tag_list.to_s.titleize %>
我們如何能作出這樣的估值:name
出現在主頁:jumbotron
:
<% content_for :jumbotron do %>
<h1>Mission</h1>
<p>
# Mission Statement Goes Here
<% @valuation_mission.each do |valuation_mission| %>
<%= valuation_mission.name %>
<% end %>
</p>
<% end %>
我認爲我們不得不寫在pages_controller的方法就像我嘗試:
class PagesController < ApplicationController
def home
@user = current_user
if logged_in?
@habits = current_user.habits
@valuations = current_user.valuations
@accomplished_goals = current_user.goals.accomplished
@unaccomplished_goals = current_user.goals.unaccomplished
@averaged_quantifieds = current_user.quantifieds.averaged
@instance_quantifieds = current_user.quantifieds.instance
@valuation_mission = current_user.valuations #We'd need to add .something to make this work?
@feed_items = current_user.feed.paginate(page: params[:page])
end
end
end
我使用的是作爲標籤的寶石,我學會了如何從這裏實現:http://railscasts.com/episodes/382-tagging
謝謝你的時間!
'current_user.valuations'應該返回所有的列表(可以是空的!)用'current_user'相關估值紀錄 – MrYoshiji
好酷我修改了問題@MrYoshiji –
你想要做什麼完全與用戶的估價?您只需執行'current_user.valuations'即可獲得它們。例如,如果你想讓每個人的名字都昏迷,那麼使用'current_user.valuations.map(&:name).join(',')' – MrYoshiji