views:

108

answers:

1

I have called the partial file form the loop. now when i update , i do not actually get updated result but need to do refresh for getting updated result. the code is like this :

the file1

  @folders.each do |@folder|
  = render :partial => 'folders/group_list'

the partial file

%div{:id => "group_list_#{@folder.id}"}  // this is the div which needs to be updated
  = group_member(@folder)   //this is the helper method

I need the updated @folder from controller but I always get file1's @folder

controller side

def any_method
  ..
  some code
  ..
  @folder = Folder.find(params[:folder_id])
  render :partial => '/folders/group_list'
end
A: 

Have you had much experience with Rails? If I'm interpreting your post correctly, you seem to be going about things in the wrong way.

It looks like you're using haml to me. If so, your files should look more like this:

file1:

= render :partial => 'folders/group_list', :collection => @folders

This renders the partial folders/group_list once for each item in @folders.

partial file:

%div{ :id => "group_list_#{group_list.id}"
    = group_member(folder)

By default, the variable accessible in the partial is named after the partial itself. So you get the id of group_list, not folder. You can modify this behavior by passing the :as argument to render().

controller:

def ajax_method
    @folder = Folder.find(params[:folder_id])
    render :update do |page|
        page.replace "group_list_#{@folder.id}", :partial => 'folders/group_list', :object => @folder
    end
end
nfm