Created
July 5, 2014 18:54
-
-
Save dan-mi-sun/9ec0b03021d2641b9d48 to your computer and use it in GitHub Desktop.
Display relevant projects for a creative based on matching skills
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% user_skills = [] %> | |
<% @user.skills.each do |skill| %> | |
<% user_skills << skill %> | |
<% end %> | |
<% @projects.each do |project| %> | |
<% project_skill = [] %> | |
<% project_skill << project.skills %> | |
<% if (user_skills & project_skill).length > 0 %> | |
<%= project.title %> | |
<% end %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I see what you're trying to do; but don't forget that all of this logic should not be in the view: under MVC we want the view to just display something; not arrive at the information that we are displaying. This should be in the model as a method and called from the controller, leaving you something to iterate over in the view.
Lines 1-4 don't seem necessary to me. What's wrong with @user.skills?
In terms of finding the projects where a certain criteria is found, this is a use for the
where
method. Try something along the lines ofNot 100% sure that will work, but the worst case scenario is you could have some kind of loop where you cross-reference the skills in a method. But do it in the model, and write a test for it.
Keep going!