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