0

Aiming to display multiple icons a user checks off when creating a new post in the view.

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 %>

*** If you have a better title I can throw up there please let me know.

enter image description here

enter image description here

enter image description here enter image description here

7
  • you mean all checkboxes result are not saving in DB ? Commented May 25, 2016 at 11:46
  • They are saving to DB - I'm looking to display the selected options in the view. Currently <%= post.tech_icon %> renders all selected options text - however the multiple option selected that i want to display are font-awesome icons not text - above I've showed how my code is. Commented May 25, 2016 at 11:49
  • what is the output of this <%= post.tech_icon %> in above case, I mean if you select more than one choice? Commented May 25, 2016 at 11:58
  • @Thorin I've updated post with an image: Depending on which one you select: fa-diamond, fa-html5 or fa-css3. if you select all of them it will show all 3 in text. Passing it into the class <i class="fa <%= post.tech_icon %>"> displays one of the icons. Commented May 25, 2016 at 12:12
  • I have added my answer I hope that will help Commented May 25, 2016 at 12:14

1 Answer 1

1

Just replace this:

  <span><i class="fa <%= post.tech_icon %>"></i></span>

with

<% post.tech_icon.split(",").each do |icon| %>
    <span><i class="fa <%= icon %>"></i></span>
 <% end unless post.tech_icon.blank? %>
Sign up to request clarification or add additional context in comments.

8 Comments

Error an undefined method `split'.
I am not able to see any image attached with this question
if your text(post.tech_icon) like this: fa-diamond fa-html5 fa-css3 then split will work
can you just add output <%= post.tech_icon %> here when you select all choices?
Yes all show when I select all options added image. Added image above under error picture
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.