views:

142

answers:

1

I am trying to render a partial onclick to save on page loading time.

<ul id="pop_twitter">
  <% @topic_count.each do |k,v| %>
  <% @k = k %>
    <!-- make a link that onclick renders a partial below -->
    <li><% link_to_remote k, ?????? %></li>
      <ul id="twitter_<%= k %>" style="display:none;">
        <!-- where the partial should load -->
      </ul>
  <% end %>
</ul>

I need to load the partial 't_tweets' and it also need the variable 'k' in from the .each loop.

+1  A: 

here's a rough start:

link_to_remote("Show", :url => {:action => 'show_tweets', :k => k})

EDIT: i guess since you're only showing a partial, it would make sense to also pass :method => :get, since link_to_remote defaults to :post.

and in your controller

def show_tweets
  render :update do |page|
  page.insert_html :bottom, 'pop_twitter', :partial => 't_tweets', :locals => params[:k]
  page["tweet_#{params[:k]}"].visual_effect :highlight #using scriptaculous
end

and your partial

<div id="<%= "tweet_#{k}" %>">
  <%= tweet.body %>
</div>
bdon
Don't forget to add update the route/resources. Otherwise the request may never reach the controller.
EmFi