Rails best_in_place gem不更新数据

时间:2014-05-07 02:01:20

标签: ruby-on-rails ruby-on-rails-4 best-in-place

我到处寻找解决方案,但是这个问题的所有常见解决方案都不适用于我。非常感谢任何帮助。

我的问题只是在我做出更改后,rails best_in_place gem不会保存我的任何数据。它允许我输入新的更改,但是在我按下Enter后它不会更新数据库(如果我刷新页面也不起作用,这是RailsCast上这个gem的初始问题)。 / p>

控制器代码:

def update
respond_to do |format|
  if @renter.update_attributes(renter_params)
    format.json { render json: @renter }
    flash[:success] = "Profile updated"
    redirect_to @renter
  else

    render 'edit'
  end

end

查看页面代码

    <li><span class="content"><b>Name: </b><%= best_in_place @renter, :name %></span></li>  

提前致谢!

编辑:从控制器添加renter_params

def renter_params
    params.require(:renter).permit(:name, :email, :password, :password_confirmation)
end

(注意:我从来没有遇到任何关于renter_params的问题,我的更新总是在数据库中保存好)

编辑:从javascripts / application.js添加代码

//= require jquery
//= require best_in_place
//= require best_in_place.purr
//= require jquery_ujs
//= require jquery.purr
//= require bootstrap
//= require turbolinks
//= require_tree .

renters.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://coffeescript.org/
jQuery ->
    $('.best_in_place').best_in_place()

1 个答案:

答案 0 :(得分:9)

如果还没有,请修改您的宝石:

gem 'best_in_place', github: 'bernat/best_in_place'
只需简单地执行gem 'best_in_place'对我不起作用。

如果这不起作用,正如documentation建议的那样,请替换:

format.json { render json: @renter }

使用:

format.json { respond_with_bip(@renter) }

respond_with_bip是一个&#34;实用程序方法,你应该在你的控制器中使用它来提供javascript方面所期望的响应,使用:json格式&#34;,文档说。我不确定这有多重要,因为我的Rails 4应用程序在没有它的情况下工作。

最后,如果update操作仅限于登录用户,请确保您已登录。