Skip to content

Instantly share code, notes, and snippets.

@redsquirrel
Forked from tjarmain/_trending.html.erb
Created August 7, 2012 18:20
Show Gist options
  • Save redsquirrel/3288035 to your computer and use it in GitHub Desktop.
Save redsquirrel/3288035 to your computer and use it in GitHub Desktop.
Trying to set up rendering of partials within tabs using AJAX
If I click on a tab it appears to render the partial, but nothing shows up:
Started GET "/trending" for 127.0.0.1 at 2012-08-07 12:19:39 -0500
Processing by ProductsController#trending as JS
Product Load (0.2ms) SELECT "products".* FROM "products"
Rendered products/_trending.html.erb (1.9ms)
Rendered products/trending.js.erb (2.5ms)
Completed 200 OK in 5ms (Views: 3.7ms | ActiveRecord: 0.2ms)
[2012-08-07 12:19:39] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
############## views/products/index.html.erb ###############
<div class="tabbable">
<ul class="nav nav-tabs" id="product-tabs">
<li class="active">
<%= link_to "Trending", trending_path, :remote => true %>
</li>
<li>
<%= link_to "Just Posted", recent_path, :remote => true %>
</li>
<li>
<%= link_to "Most Popular", popular_path, :remote => true %>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="trending">
</div>
<div class="tab-pane" id="recent">
</div>
<div class="tab-pane" id="popular">
</div>
</div>
</div>
class ProductsController < ApplicationController
# GET /products
# GET /products.json
def index
@products = Product.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @products }
format.js { render :layout => false }
end
end
def trending
@products = Product.all
respond_to do |format|
format.js
end
end
def recent
@products = Product.all
respond_to do |format|
format.js
end
end
def popular
@products = Product.all
respond_to do |format|
format.js
end
end
end
################# routes.rb ##################
Behova::Application.routes.draw do
root :to => 'products#index'
resources :products
get 'trending' => 'products#trending', :as => 'trending'
get 'recent' => 'products#recent', :as => 'recent'
get 'popular' => 'products#popular', :as => 'popular'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment