tom*_*tom 3 ruby-on-rails best-in-place ruby-on-rails-4
我到处寻找解决方案,但是这个问题的所有常见解决方案都不适用于我.任何帮助是极大的赞赏.
我的问题只是在我做出改变之后,rails best_in_place gem没有保存我的任何数据.它允许我输入新的更改,但是在我按下回车后它不会更新数据库(如果我刷新页面也不起作用,这是RailsCast上这个gem的初始问题).
控制器代码:
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
Run Code Online (Sandbox Code Playgroud)
结束
查看页面代码
<li><span class="content"><b>Name: </b><%= best_in_place @renter, :name %></span></li>
Run Code Online (Sandbox Code Playgroud)
提前致谢!
编辑:从控制器添加renter_params
def renter_params
params.require(:renter).permit(:name, :email, :password, :password_confirmation)
end
Run Code Online (Sandbox Code Playgroud)
(注意:我的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 .
Run Code Online (Sandbox Code Playgroud)
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()
Run Code Online (Sandbox Code Playgroud)
如果您还没有,请修改您的宝石,如下所示:
gem 'best_in_place', github: 'bernat/best_in_place'
Run Code Online (Sandbox Code Playgroud)
通过简单的做gem 'best_in_place'就没有为我工作.
如果这不起作用,如文档所示,替换:
format.json { render json: @renter }
Run Code Online (Sandbox Code Playgroud)
有:
format.json { respond_with_bip(@renter) }
Run Code Online (Sandbox Code Playgroud)
respond_with_bip是一个"应该在你的控制器中使用的实用方法,以便提供javascript方面所期望的响应,使用:json格式",文档说.我不确定这有多重要,因为我的Rails 4应用程序在没有它的情况下工作.
最后,如果update操作仅限于登录用户,请确保您已登录.
| 归档时间: |
|
| 查看次数: |
1635 次 |
| 最近记录: |