如何根据标签调用text_field?

How to call a text_field based on tag?

我不知道这是否可行,但如果用户在评估表中创建一个名为 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

我正在使用 acts-as-taggable-on gem,我从这里学习了如何实现它:http://railscasts.com/episodes/382-tagging

感谢您的宝贵时间!

你可以使用这个:

current_user.valuations.tagged_with('mission-statement')

在文档中找到:https://github.com/mbleigh/acts-as-taggable-on#finding-tagged-objects