Как вызвать text_field на основе тега?

Я не знаю, возможно ли это, но если пользователь создает тег под названием 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-tagged-on, который я узнал, как реализовать здесь: http://railscasts.com/episodes/382-tagging

Спасибо за ваше время!


person AnthonyGalli.com    schedule 07.04.2015    source источник
comment
current_user.valuations должен возвращать список всех (может быть пустым!) записей оценки, связанных с current_user   -  person MrYoshiji    schedule 07.04.2015
comment
Хорошо, круто, я пересмотрел вопрос @MrYoshiji   -  person AnthonyGalli.com    schedule 07.04.2015
comment
Что именно вы хотите сделать с оценками пользователя? Вы уже получаете их, просто выполняя current_user.valuations. Если вы хотите получить все их имена с запятой между ними, например, используйте current_user.valuations.map(&:name).join(', ')   -  person MrYoshiji    schedule 07.04.2015
comment
Я пытаюсь получить оценки @MrYoshiji только с тегом: заявление о миссии.   -  person AnthonyGalli.com    schedule 07.04.2015
comment
Что возвращает current_user.valuations? Массив строк? Если да, то current_user.valuations.select{ |tag| tag.match(/mission-statement/) }   -  person MrYoshiji    schedule 07.04.2015
comment
Спасибо @MrYoshiji! Вы на правильном пути, за исключением того, что я получаю undefined method 'match' for #<Valuation:0x007f921ab002a8>. В моей миграции у меня есть это в отношении тегов: create_table :tags do |t| t.string :name end. Надеюсь, это полезно!   -  person AnthonyGalli.com    schedule 07.04.2015


Ответы (1)


Вы можете использовать это:

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

Найдено в документации: https://github.com/mbleigh/acts-as-tagged-on#finding-tagged-objects

person MrYoshiji    schedule 07.04.2015