【问题标题】:In place editing rails就地编辑导轨
【发布时间】:2017-10-17 09:02:11
【问题描述】:

我收到错误数量的参数错误(给定 1,预期 2..3)我如何在每个循环中应用它?我希望能够在每个循环中就地编辑它

  <%= best_in_place s.message %>

application.js

//= require jquery_ujs
//= require jquery.purr

user.coffee

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

版本 best_in_place 3.1.1

有没有更好的方法来实现就地编辑

【问题讨论】:

  • 你想做什么?,你传递的只是一个可能是占位符的值。
  • @SebastiánPalma 我希望能够就地编辑消息

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


【解决方案1】:
best_in_place(object, field, opts = {})

查看best_in_place 方法期望接收的参数。你只通过了一个。

  • object 表示对象或特定记录。
  • field 是要编辑的属性 - 在您的情况下,它可能是 message
  • options 它接受的所有options

很可能你需要类似的东西:

<%= best_in_place @object, :message, as: :input %>

【讨论】:

  • 它返回错误 undefined method `message' 似乎 :message 被视为一种方法?我把它放在每个循环之外
  • @admin 的值是多少?
  • @admin = Message.where(id: current_user)
  • 无论何时使用where,它都会返回一个ActiveRecord_Relation,这就是为什么这种对象没有名为message 的方法,您需要访问单个对象,就像我一样已指出object 表示对象或特定记录。要检查,请尝试使用Message.where(id: current_user).first
  • 最后一个问题有什么办法可以将它放在每个循环中吗?
猜你喜欢
  • 1970-01-01
  • 2013-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多