Hello
I do not understand how to use instance variable properly with partial views, I am hoping someone here can enlighten me. For example
class MainController < ApplicationController def index @item_list = Item.find_all_item end
def detail\_display @current\_selected = @item= Item\.find\(params\[:id\]\) redirect\_to :action => :index end
end
detail_display is invoked when the user clicks on an item in the list. The variable @current_selected is not available to the partial view invoked when the index is redirected to. How can I remedy this?
The key thing you need to understand here is that this is an http redirect, ie a separate request: by the time the index action is rendered the controller object that had the @current_selected instance variable has been destroyed and your request is being handled by a completely fresh controller object. If the index action needs to know what the currently selected object is then you need to pass a parameter to it telling it this. In this light, I'm not sure what the point of the detail_display action is as it seems to be a complete no- op.
Fred