I am using Ruby on Rails 3.0.7 and I would like to understand how can I handle the following situation to avoid the istance variable @photo overriding on loading the view.
In my view file I have:
<div>
<%=
render :partial => 'user/photos',
:locals => {
:photo => @photo = 'test_photo1.jpg',
}
%>
</div>
<div>
<%=
render :partial => 'user/photos',
:locals => {
:photo => @photo = 'test_photo2.jpg',
}
%>
</div>
If I load the above view I have a strange behavior on outputting. That seams that the @photo class is overwritten (by the second rendering statement) when the page loads. Of course if I make only one rendering all works.
How can I solve the above problem in order to properly pass variables?
Note: I can not change the @photo name. That is, it must be the same for both partial templates.
I also tryed this version just deleting the @photo variable
<div>
<%=
render :partial => 'user/photos',
:locals => {
:photo => 'test_photo1.jpg',
}
%>
</div>
<div>
<%=
render :partial => 'user/photos',
:locals => {
:photo => 'test_photo2.jpg',
}
%>
</div>
but that still doesn’t work.
Try that, I dont know why you had
:photo => @photo = 'test_photo2.jpg'Also see the Rails guides on partials. They really let you have a good grasp of the basics.