我按照 Ryan Bates 对最佳就地宝石的railscast进行了操作,但无法使其正常工作。我在 user.rb 模型中设置 before_create 的默认值显示在页面上,但我无法单击它进行编辑;它只是显示为静态元素。虽然,Firebug 显示 best_in_place javascript 正在视图中加载<head>
。
应用程序.js
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require jquery-ui
//= require jquery.purr
//= require best_in_place
//= require_tree .
users.js.coffee
jQuery ->
$('.best_in_place').best_in_place()
用户.rb
attr_accessible :email, :name, :password, :password_confirmation, :avatar, :goal
...
before_create :default_values
...
private
def default_values
self.goal ||= "Write Current Goal Here"
end
users_controller.rb
respond_to :html, :json
...
def update
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
format.html {
flash[:success] = "Profile updated"
sign_in @user
redirect_to @user
}
format.json { respond_with_bip(@user) }
else
format.html { render 'edit' }
format.json { respond_with_bip(@user) }
end
end
end
用户/show.html.erb
...
<%= best_in_place @user, :goal %>