jquery - 使用 best_in_place gem

标签 jquery rubygems ruby-on-rails-3.1

我正在尝试使用 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()

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 

.

gem 文件

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

最佳答案

删除:posts.js.coffee

将此添加到您的 posts/show.html.erb 代码下方:

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

关于jquery - 使用 best_in_place gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8497935/

相关文章:

ruby - Compass/SASS 中缺少依赖项

ruby-on-rails - Magento API : get products from a category

ruby-on-rails-3 - 如何在助手的子类中捕获 block ?

javascript - 搜索结果链接

Ruby Gems 无法运行

jquery - 多页 jQuery 图片库

ruby - 无法使用 ruby​​ 2.0 安装 bundler 1.3.0

ruby-on-rails - 关联语法 ruby​​ on rails 复数

javascript - 在javascript中在图像上绘制矩形

javascript - 检查按下的空间,然后使用多语言的 jquery 添加 diez 标签