2011-12-13 76 views
1

我試圖使用best_in_place寶石,但它似乎並不奏效。我遵循railscast教程,但現在運氣好。當我說這是行不通的,我的意思是,沒有選項編輯屏幕上的任何內容。以默認導軌方式顯示。使用best_in_place寶石

帖子/ show.html.erb

<p id="notice"><%= notice %></p> 

<p> 
    <b> 
    <%= best_in_place @post, :title %> 
    </b> 
</p> 

<p> 
    <%= best_in_place @post ,:content, :type => :text_area %> 
</p> 

<p> 
    <b>Featured:</b> 
    <%= best_in_place @post , :featured, :type => :check_box %> 
</p> 


<%= link_to 'Edit', edit_post_path(@post) %> | 
<%= link_to 'Back', posts_path %> 

posts.js.coffee

# Place all the behaviors and hooks related to the matching controller here. 
# All this logic will automatically be available in application.js. 
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ 

jQuery -> 
    $('.best_in_place').best_in_place() 

的application.js

// This is a manifest file that'll be compiled into including all the files listed below. 
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically 
// be included in the compiled file accessible from http://example.com/assets/application.js 
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 
// the compiled file. 
// 
//= require jquery 
//= require jquery_ujs 
//= require jquery.purr 
//= require best_in_place 
//= require_tree 

的Gemfile

source 'http://rubygems.org' 

gem 'best_in_place' 
gem 'rails', '3.1.3' 

gem 'pg' 
gem "paperclip" 

group :assets do 
    gem 'sass-rails', '~> 3.1.5' 
    gem 'coffee-rails', '~> 3.1.1' 
    gem 'uglifier', '>= 1.0.3' 
end 

gem 'jquery-rails' 

group :test do 
    # Pretty printed test output 
    gem 'turn', '0.8.2', :require => false 
end 
+0

在您的瀏覽器中查看任何Javascript錯誤?您可能必須使用Firebug或在Chrome中啓用開發人員工具。 – rkb 2011-12-24 23:06:52

+0

我只是說best_in_place和像你注意到沒有圖標。雖然當我真正點擊該字段時,它變得可編輯。原來我沒有CSS(也許我錯過了一個步驟)。查看http://bipapp.heroku.com/users/45,瞭解一些您可以使用的CSS示例。這是來自開發人員的演示。 – Adam21e 2012-02-16 06:01:23

回答

1

刪除:posts.js.coffee

添加此下方的posts/show.html.erb代碼:

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

你能告訴我們你的posts_controller.rb?請確保它responds_to:JSON,更具體地說確保更新動作指定JSON respond_with_bip(@post)。

如果不顯示再嘗試這樣的模型post.rb設置默認值:

before_create :default_values 

    private 

    def default_values 
     self.post ||= "Write Post Here" 
    end