I am stuck at passing a variable value from controller to partial. I have all the data from skill set database on @skillSetData coming from controller: SkillSetsController
def skillsetdata
@skillSetData = SkillSet.all
end
The code below on skill_set/skillsetdata.html.erb display all the data.
<% @skillSetData.each do |single_skill| %>
<option value="<%= single_skill.skillname %>"><%=single_skill.skillname %></option>
<% end %>
But I am not able to pass the variable if skillsetdata.html.erb is a partial ie: _skillsetdata.html.erb. The code for the _skillsetdata I have written is:
<% skills_set_data.each do |single_skill| %>
<option value="<%= single_skill.skillname %>">
<%=single_skill.skillname %>
</option>
<% end %>
I want to make it partial because it has the dropdown list that has to be rendered on various other pages. One of the pages that I want to use on is:static_pages/home.html.erb which is from different controller ie: staticPages. The code that I have tried after the help is:
<%= render partial: 'skill_sets/skillsetdata', locals: { skills_set_data:@skillSetData } %>
But I am getting error as: undefined method `each' for nil:NilClass in skill_sets/_skillsetdata.html.erb while trying to load home.html.erb. I am not able to pass data between different pages from a partial.
Any help with example code would be helpful.
ActionController::UnknownFormatis a different error. What's the code in your controllers?Missing partial, if the local variable setted doesn't match in name in the partial thenundefined local variable or methodif @skillSetData is nil thenundefined method 'each' for nil:NilClass. Give it a try, uselocals: { skills_set_data: nil }and see what happens.