2011-10-13 89 views
2

我有一個功能,可以讓用戶添加課程到他們的購物車。在開發中一切正常:當用戶點擊「添加到購物車」圖標時,它會在購物車中創建一個line_item對象,並且carts_controller執行一個AJAX請求,以加載該購物車的更新後的html。下面的代碼:然後Heroku not loading ajax calls

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 } 

的format.js引用create.js.erb文件:

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

這拉動了@cart部分,它包含新插入的LINE_ITEM。

但是,當我將這個文件上傳到heroku時,代碼的這部分內容被破壞了。當我點擊「添加到購物車」圖標時,會創建line_item,但在顯示購物車之前頁面必須刷新。

在識別這種AJAX調用之前,我有必須在heroku中做些什麼嗎?

謝謝!

+0

不,你並不需要什麼具體的你的AJAX工作在Heroku.Just確保你正確地在你的文件中包含prototype.js或者prototype.js存在於你的應用程序文件夾中 – Salil

回答

0

您可能需要預編譯您的資產。

在本地運行RAILS_ENV=production bundle exec rake assets:precompile。這將在公共目錄中創建一個assests文件夾。添加所有這些,並將其提交給heroku。

1

對我來說,解決辦法是改變:

配置/環境/ production.rb

config.assets.compile = true 

(是 '假')