【问题标题】:Using best_in_place gem使用 best_in_place gem
【发布时间】:2012-01-19 20:11:16
【问题描述】:

我正在尝试使用 best_in_place gem,但它似乎不起作用。我遵循了 railscast 教程,但现在很幸运。当我说它不起作用时,我的意思是没有选项可以编辑屏幕上的任何内容。以默认的 rails 方式出现。

posts/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()

应用程序.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 

.

宝石文件

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

【问题讨论】:

  • 在您的浏览器中看到任何 Javascript 错误?您可能需要使用 Firebug 或在 Chrome 中打开开发者工具。
  • 我刚刚添加了 best_in_place,就像您注意到没有图标一样。尽管当我实际单击该字段时,它变得可编辑。原来我没有 CSS(也许我错过了一步)。检查bipapp.heroku.com/users/45 以获取您可以使用的一些示例 CSS。这是开发人员的演示。

标签: jquery rubygems ruby-on-rails-3.1


【解决方案1】:

删除:posts.js.coffee

在您的posts/show.html.erb 代码下方添加:

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

【讨论】:

    【解决方案2】:

    你能告诉我们你的posts_controller.rb吗?确保它 respond_to :json,更具体地说,确保 Update 操作为 json 指定 respond_with_bip(@post)。

    如果没有显示,请尝试在模型 post.rb 中设置默认值:

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

    【讨论】:

      【解决方案3】:

      我正在为 Rails 中的类似问题寻找解决方案。我在Rails 3.1 Assets - Strange Serving in Development找到了一些答案

      这对我来说很好。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-06
        • 1970-01-01
        • 2013-03-06
        • 2012-11-15
        • 1970-01-01
        • 1970-01-01
        • 2012-04-11
        • 2014-06-23
        相关资源
        最近更新 更多