首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用best_in_place gem

使用best_in_place gem
EN

Stack Overflow用户
提问于 2011-12-14 07:54:23
回答 3查看 2K关注 0票数 1

我正在尝试使用best_in_place gem,但它似乎不起作用。我学习了railscast教程,但现在很幸运。当我说它不工作时,我的意思是没有在屏幕上编辑任何东西的选项。以默认的rails方式显示。

posts/show.html.erb

代码语言:javascript
复制
<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

代码语言:javascript
复制
# 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

代码语言:javascript
复制
// 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

代码语言:javascript
复制
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
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-09-04 04:01:57

删除:posts.js.coffee

在您的posts/show.html.erb代码下面添加以下内容:

代码语言:javascript
复制
$(document).ready(function() {
  /* Activating Best In Place */
  jQuery(".best_in_place").best_in_place();
});
票数 1
EN

Stack Overflow用户

发布于 2012-02-18 01:29:44

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

这对我来说很好。

票数 1
EN

Stack Overflow用户

发布于 2012-07-17 22:43:57

你能给我们看看你的posts_controller.rb吗?确保它为responds_to :json,更具体地说,确保更新操作为json指定了respond_with_bip(@post)。

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

代码语言:javascript
复制
before_create :default_values

  private

    def default_values
      self.post ||= "Write Post Here"
    end
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8497935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档