I have code in rails 4.2.3 where on the index page of the dropbox connect feature, it creates a list of the files in the user's root dropbox directory once logged in. This is the code:
def index
druidbox = current_user.dropbox_session if current_user.dropbox_session
# find the current user's dropbox_session from the database
if current_user.dropbox_session
dbsession = DropboxSession.deserialize(current_user.dropbox_session)
# create the dropbox client object
@client = DropboxClient.new(dbsession, DROPBOX_APP_MODE).metadata('/')
end
end
In this list created, you can see and download any files at the root level. You can see any directory at the root level. The directory is even linked but when clicked, it refreshes the page but doesn't change the contents of the view. This is the code I have in the index view:
<tbody>
<% @client["contents"].each do |key, value| %>
<tr>
<td>
<% if (key["is_dir"]) %>
<%= "<div class='glyphicon glyphicon-folder-open'></div> ".html_safe %>
<%= link_to key["path"][1..-1], dropbox_path_change_path(path: key["path"]) %>
<%else %>
<%= key["path"][1..-1]%>
<%= link_to "[#{key["size"]} <div class='glyphicon glyphicon-cloud-download'></div>]".html_safe, dropbox_download_path(path: key["path"]), :target => "_blank" %>
<%end%>
</td>
</tr>
<%end%>
<%end%>
</tbody>
dropbox_path_change_path is just a partial that reloads the index. I was thinking that when someone clicks on the link for a folder, it would reload the index but list the contents of the directory the link goes to.
How do I display the contents of the folder on the index page when the link is clicked?