I can't seem to access instance objects in partials. Example:
In controller I have:
ActiveAdmin.register Store do
sidebar "Aliases", :only => :edit do
@aliases = Alias.where("store_id = ?", params[:id])
render :partial => "store_aliases"
end
end
Then in the _store_aliases.html.erb partial I have:
<% @aliases.each do |alias| %>
<li><%= alias.name %></li>
<% end %>
This doesn't work. The only thing that does work (which is horrible to do as I'm putting logic in a view is this:
<% @aliases = Alias.where("store_id = ?", params[:id]) %>
<% @aliases.each do |alias| %>
<li><%= alias.name %></li>
<% end %>
You have to pass your instance variable to your partial in order to use it there:
Then in your partial you will be able to use it as local variable
When rendering a partial you need to actively define the variables that are given to that partial. Change your line
to
Inside your partial the variables is then accessible as a local variable (not an instance variable!). You need to adjust your logic inside the partial by removing the
@
.For further reading have a look at the API documentation (specifically the section "3.3.4 Passing Local Variables").