【问题标题】:Rails + best_in_place + Twitter BootstrapRails + best_in_place + Twitter Bootstrap
【发布时间】:2013-03-28 07:43:03
【问题描述】:

我对最佳位置和 Twitter 引导程序有一个非常烦人的问题。我已经花了很多时间。我已经浏览了好几页 - best_in_place github 页面和问题。所以我想,我修复了它但没有,我不知道错误在哪里。

当我使用 best_in_place 进行第一次编辑时,它会起作用,保存值并将输入更改回具有新值的“正常”视图。但是当我想第二次做同样的动作(编辑它)时,它不起作用。我必须重新加载页面,然后我只能再次编辑它一次。我的代码如下:

AccountsController.rb

def update
    @account = current_user.account
    respond_to do |format|
      if @account.update_attributes(params[:account])
        format.json { respond_with_bip(@account) }
      else
        format.json { respond_with_bip(@account) }
      end
    end
  end

查看

<%= best_in_place current_user.account, :introduction, :type=> :input,
        :nil => "Click me to add your introduction!", 
                :html_attrs => {:'data-provide' => "typeahead" } %>

account.js.coffee

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

我已经看过这个页面,但没有找到答案: SO Thread、ExampleApp、Best_in_place Issue

请问,有人可以帮我吗?我知道这可能是由 Twitter Bootstrap 引起的,但我不知道如何解决它:(

【问题讨论】:

  • 输入框第二次到位了吗?
  • 我找到了答案。请检查下面的答案。
  • 这不是 twitter bootstrap 造成的。所有引导程序所做的就是将样式应用于元素。基于 Rails 4 和 Bootstrap 3,您需要 respond_with_ip(@object) 才能使其工作。
  • 这是 2.5 岁的问题。我认为这个评论无关紧要

标签: ruby-on-rails-3 twitter-bootstrap bootstrap-typeahead best-in-place


【解决方案1】:

好的,我已经找到了解决方案。 “问题”在这一行:

format.json { respond_with_bip(@account) }

我将其替换为:

format.json { render json: @account}

它现在可以工作了。但这只是运气。有谁知道这里的主要区别是什么?为什么一个工作,第二个没有? respond_with_bip 到底有什么作用?

【讨论】:

  • BIP 只是对您的更新操作进行 AJAX 调用。渲染 json 允许控制器将值返回给您的审阅。 Best in PLace 只是简单地将 AJAX 层放在您的视图上——因此从控制器级别来看,没有任何特定于 BIP 的内容,因此只需要渲染 json。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多