为了显示多个图标,用户在视图中创建新帖子时会进行检查。
new.html.erb
<%= check_box_tag 'post[tech_icon][]', 'fa-diamond', checked('fa-diamond'), id: "message_area" %>
<%= check_box_tag 'post[tech_icon][]', 'fa-html5', checked('fa-html5'), id: "message_area" %>
<%= check_box_tag 'post[tech_icon][]', 'fa-css3', checked('fa-css3'), id: "message_area" %>
show.html.view
<% current_user.posts.each do |post| %>
* bellow only renders one checked selections (the last one checked)
<span><i class="fa <%= post.tech_icon %>"></i></span>
* bellow just renders the selected option text on the screen
<%= post.tech_icon %>
<% end %>
***如果你有更好的头衔,我可以告诉我。
答案 0 :(得分:1)
只需替换它:
<span><i class="fa <%= post.tech_icon %>"></i></span>
带
<% post.tech_icon.split(",").each do |icon| %>
<span><i class="fa <%= icon %>"></i></span>
<% end unless post.tech_icon.blank? %>