0

我想在我的Rails應用中實現best_in_place,我無法弄清楚如何實現它。當我滾動需要編輯的文本時,它不會做任何事情。我在用戶下有一個嵌套的配置文件模型,我想編輯用戶名。但名字在Profile Model下。所以我有「user.profile.name」。我已經介紹了安裝步驟,幷包含並安裝了gem,並在我的application.js中包含了jquery文件,如前所述!Rails Best_in_place編輯問題

這裏是我的節目的看法:

<%= best_in_place @profile, :name, :type => :input, :path => user_profile_path(@user) %> 

這裏是我的節目在用戶控制器動作:

def show 
    @user = User.find_by_identifier!(params[:id]) 
    @profile = @user.profile 
    end 

這裏是我的配置控制器:

的respond_to:HTML,:JSON

def edit 
    @user = User.find_by_identifier!(params[:user_id]) 
    @profile = @user.profile 
    end 

    def update 
    @user = User.find_by_identifier!(params[:user_id]) 
    @profile = @user.profile 
    @profile.update_attributes(params[:profile]) 
    respond_with @user 
    end 

這是我的application.js文件

//= require jquery 
//= require jquery_ujs 
//= require best_in_place 
//= require best_in_place.purr 
//= require_tree . 

$(document).ready(function() { 
    /* Activating Best In Place */ 
    jQuery(".best_in_place").best_in_place(); 
}); 
+0

單擊名稱時出現文本框?如果是,編輯名稱後控制檯中有什麼? – Baldrick

+0

不出現任何內容。它就像我甚至沒有安裝最好的地方?它做nohing。只需顯示名稱就像它的硬編碼! – pratski

+0

如果未安裝best_in_place,則在視圖呈現在<%= best_in_place ...%>'的過程中會出現錯誤。這當然是一個JavaScript問題。你應該檢查頁面加載時是否存在javascript錯誤,best_in_place javascript文件存在,並且可能需要調試才能找到問題所在: -/ – Baldrick

回答

0

多虧了@baldrick。我有另一個jQuery插件,它使用的是舊版本的jQuery。我刪除了與該插件相關的JS,然後Best_in_Place正常工作。唯一的問題是我必須使用其中一個或另一個,因爲它們發生衝突,或者找到另一個插件使用更新版本jQuery的方式,因爲新版本不支持某些功能。