我不知道这是否可行,但如果用户在评估表单中创建了一个名为mission-statement的标记:
<%= 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
我正在使用act-as-taggable-on gem,我从这里学会了如何实现:http://railscasts.com/episodes/382-tagging
感谢您的时间!
答案 0 :(得分:1)
您可以使用:
current_user.valuations.tagged_with('mission-statement')
在文档中找到:https://github.com/mbleigh/acts-as-taggable-on#finding-tagged-objects