i am creating a simple shopping cart but when i click add to cart i am getting a message error saying OrderItemsController#create is missing a template for this request format and variant. request.formats: ["text/html"] request.variant: []
i have orderitem route setup and the create.js.erb file setup i dont understand why i am getting this error any solution here my code.
errror message
"\nrequest.variant: #{request.variant.inspect}"
raise ActionController::UnknownFormat, message
elsif interactive_browser_request?
message = "#{self.class.name}\##{action_name} is missing a template " \
"for this request format and variant.\n\n" \
orderItem.controller.rb
class OrderItemsController < ApplicationController
def create
@order = current_order
@order_item = @order.order_items.new(order_item_params)
@order.save
session[:order_id] = @order.id
end
def update
@order = current_order
@order_item = @order.order_items.find(params[:id])
@order_item.update_attributes(order_item_params)
@order_items = @order.order_items
end
def destroy
@order = current_order
@order_item = @order.order_items.find(params[:id])
@order_item.destroy
@order_items = @order.order_items
end
private
def order_item_params
params.require(:order_item).permit(:product_id, :quantity)
end
end
create.js.erb
<% if @order.errors.any? || @order_item.errors.any? %>
alert("Invalid")
<% else %>
$(".cart").html("<%= escape_javascript(render 'layouts/cart') %>")
<% end %>
route
Rails.application.routes.draw do
resources :products
resources :order_items
resource :carts, only: [:show]
root 'welcomes#index'
devise_for :users
# For details on the DSL available within this file, see http://ift.tt/GVpneB
end
_cart.html.erb
<%= link_to "#{current_order.order_items.size} items in card and price #{current_order.subtotal}", carts_path %>
Aucun commentaire:
Enregistrer un commentaire