locals in rails partial -
i have partial:
<% if flash.any? %> <% flash.each |type, message| %> <%= render 'shared/flash_message', locals: { type: type, message: message } %> <% end %> <% end %>
which including partial:
<div class="message-box message-box--<%= type %>"> <a class="close" data-dismiss="alert">×</a> <%= message %> </div>
when running get:
undefined local variable or method `type' for
<#:0x007fe510aa3c80>
it's pointing error outputting <%= type %> know why?
you have specify rendering partial pass in local variables.
so change
<%= render 'shared/flash_message', locals: { type: type, message: message } %>
to
<%= render partial: 'shared/flash_message', locals: { type: type, message: message } %>.
http://guides.rubyonrails.org/layouts_and_rendering.html#passing-local-variables
Comments
Post a Comment