Created
March 6, 2014 04:41
-
-
Save johnkoht/9382805 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$('<%= j render partial: "cart_form", locals: {product: @product} %>').modal('show'); |
This file contains hidden or 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
# This file already exists, you'll just append to it... | |
Spree::ProductsController.class_eval do | |
respond_to :js, :html | |
# custom method/endpoint that our ajax call will hit. This will respond to the ajax call and render | |
# a template in spree/products/add_to_cart.js.erb and you're @product varaible will be available | |
def add_to_cart | |
@product = Spree::Product.find(params[:id]) | |
# No need for this. | |
# render partial: "spree/products/cart_form", locals: {product: @product} | |
end | |
end |
This file contains hidden or 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
# This adds a method to products called "add_to_cart" to the member (individual resource). If you run | |
# rake routes in your console you'll see it requires an id #=> /products/:id/add_to_cart | |
resources :products, only: [] do | |
get :add_to_cart, on: :member | |
end |
This file contains hidden or 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
-# Let's use a link tag and utilize Rails's Ujs AJAX mechanism. The remote: true will make this into an ajax | |
-# call to the server with the application/js data type. (see the controller below) | |
= link_to "BUY", add_to_cart_product_path(product.id), remote: true, class: "btn btn-secondary pull-left" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment