I am trying to render a partial from within a js.erb file which has both a collection AND a local variable passed to it. Everything works fine except I cannot access the local variable in the view. I have tried the following:
<%= escape_javascript(render(partial: 'tasks/task', collection: @task_group.tasks_belonging_to, as: :task, locals: {testvble: "bob"})) %>
<%= escape_javascript(render(partial: 'tasks/task', collection: @task_group.tasks_belonging_to, locals: {testvble: "bob"})) %>
<%= escape_javascript(render(partial: @task_group.tasks_belonging_to, locals: {testvble: "bob"})) %>
<%= escape_javascript(render(@task_group.tasks_belonging_to, testvble: "bob")) %>
Each of the above works until I try to access the local variable in the view. I get the error:
undefined local variable or method `testvble'
Just for completeness, each of the above is inside the following statement in the js.erb file (at the xxxx position):
$("#task-group-<%=@task_group.id%>").append("xxxx").hide().show('slow')
This is the code in the partial causing the issue:
<p>should be bob:<%= testvble %></p>