I have a change avatar popup in my ruby on rails application. I'm trying to use it for several models like changing profile picture or picture of a product.
I have created a view and trying to open it with parameters as follows in the user.html.erb file:
<div id="myModal_change_avatar" class="modal-dialog fade-scale">
<div class="modal-content">
<div style="height: 100%;width: 100%" id="id_model_content">
<%= render partial: 'change_avatar/index', locals: { par:'param'} %>
</div>
</div>
</div>
In my _index.html.erb file which is located under views/change_avatar:
<h1><%= par %></h1>
But, I get "undefined local variable or method `par' for" when I open user.html.erb file.
I can't see what I'm missing.
Any suggestions ?
Thanks.
I have also experienced this issue in the past and not entirely sure what causes it but in my case, it seemed to be related to deeply nested partials (but only for a few views).
The solution is to access the local variable from the local_assigns hash. What I tend to do is assign it to a local variable at the top of the page as so:-
<% par ||= local_assigns[:par] %>
Hope this helps.