Created
August 7, 2012 17:26
-
-
Save tjarmain/3287526 to your computer and use it in GitHub Desktop.
Trying to set up rendering of partials within tabs using AJAX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############## views/products/_trending.html.erb ############### | |
<% @products.each do |product| %> | |
<div class="product"> | |
<%= link_to (image_tag product.thumbnail), product %> | |
<div class="product-overlay-details"> | |
<%= product.name %>... | |
</div> | |
</div> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############## 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############## views/products/trending.js.erb ############### | |
$('#trending').html("<%= escape_javascript(render('trending')) %>"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment