开发者

Heroku not loading ajax calls

开发者 https://www.devze.com 2023-04-12 21:01 出处:网络
I have a feature that lets users add courses to their shopping cart. Everything works fine in development: when a user clicks on the \"add to cart\" icon, it creates a line_item object in the cart, an

I have a feature that lets users add courses to their shopping cart. Everything works fine in development: when a user clicks on the "add to cart" icon, it creates a line_item object in the cart, and the carts_controller executes an AJAX request that loads the updated html for the cart. Here's the code:

  def create
    @user = current_user
    @cart = @user.cart
    @line_item = @cart.line_items.build(params[:line_item]) 

    respond_to do |format|
      if @line_item.save
        format.html { redirect_to(root_path, :notice => 'Course added to 开发者_高级运维cart') }
        format.js { @current_item = @line_item }
        format.xml  { render :xml => @line_item, :status => :created, :location => @line_item }

The format.js then references the create.js.erb file:

$("#cart").html("<%= escape_javascript(render(@cart)) %>");

This pulls in the @cart partial, which contains the newly inserted line_item.

When I uploaded this to heroku, however, this part of my code broke. When I click on the "add to cart" icon, the line_item is created, but the page has to refresh before it shows the cart.

Is there something I have to do within heroku before it recognizes this kind of AJAX call?

Thanks!


for me, the solution was to change:

config/environments/production.rb

config.assets.compile = true

(was 'false')


You might need to pre-compile your assets.

run RAILS_ENV=production bundle exec rake assets:precompile locally. This will create a assests folder in the public directory. add all of them and commit that to heroku.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号