0

我正在尝试将 type = select 与 gem 'bootstrap-editable-rails' 一起使用。

该字段弹出并有一个选择框,但值不显示。

任务记录有一个外键 = rating_id,我想从评级表中显示的值是 = ratingname

这是我的视图代码:

<a href="#" class="answer" data-type="select" data-placement="right"  data-resource="task" data-source="/ratings" data-name="ratingname" data-url="/tasks/<%= task.id %>" data-original-title="Select Rating">
  <%= textarea_format(task.rating.ratingname) %>
</a>

更新 1

我是否必须更改 rating.json 以包含“文本”和“值”?

更新 2

我像这样使用RABL:

object @rating
attributes :id => :id, :ratingname => :text, :ratingvalue => :value

现在选择值出现了!

但是,我得到这个错误:

`call'
(gem) journey-1.0.4/lib/journey/router.rb:68:in `block in call'
- (gem) journey-1.0.4/lib/journey/router.rb:56:in `call'
- (gem) actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:601:in `call'
- (gem) rack-pjax-0.7.0/lib/rack/pjax.rb:12:in `call'
- (gem) meta_request-0.2.2/lib/meta_request/middlewares/app_request_handler.rb:11:in `call'
- (gem) rack-contrib-1.1.0/lib/rack/contrib/response_headers.rb:17:in `call'
- (gem) meta_request-0.2.2/lib/meta_request/middlewares/headers.rb:16:in `call'
- (gem) meta_request-0.2.2/lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
- (gem) pdfkit-0.5.3/lib/pdfkit/middleware.rb:16:in `call'
- (gem) warden-1.2.1/lib/warden/manager.rb:35:in `block in call'
- (gem) warden-1.2.1/lib/warden/manager.rb:34:in `call'
- (gem) actionpack-3.2.12/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
- (gem) rack-1.4.5/lib/rack/etag.rb:23:in `call'
- (gem) rack-1.4.5/lib/rack/conditionalget.rb:35:in `call'
- (gem) actionpack-3.2.12/lib/action_dispatch/middleware/head.rb:14:in `call'
- (gem) remotipart-1.0.5/lib/remotipart/middleware.rb:30:in `call'
- (gem) actionpack-3.2.12/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
- (gem) actionpack-3.2.12/lib/action_dispatch/middleware/flash.rb:242:in `call'
- (gem) rack-1.4.5/lib/rack/session/abstract/id.rb:210:in `context'
- (gem) rack-1.4.5/lib/rack/session/abstract/id.rb:205:in `call'
- (gem) actionpack-3.2.12/lib/action_dispatch/middleware/cookies.rb:341:in `call'
- (gem) activerecord-3.2.12/lib/active_record/query_cache.rb:64:in `call'

...

更新 3

我几乎让它工作了。

我的 RABL:

object @rating
attributes :ratingname => :text, :id => :value

我将 ratingname 作为下拉列表!选择值时会发生以下情况!

UPDATE "tasks" SET "rating_id" = 2, "updated_at" = '2013-03-28 08:21:36.869872' WHERE "tasks"."id" = 36

所以,下拉列表好,更新好。

但是,带有评级选择列表的弹出框变成红色并且不会消失!并且浏览器控制台中没有错误。

在此处输入图像描述

4

2 回答 2

0

让它工作。我不得不更改更新部分中任务的控制器。

From:     format.json { head :ok }
To:       format.json { render json: @task }
于 2013-03-28T15:25:19.870 回答
-1

有时你可能会遇到js冲突,所以检查控制台

未捕获的类型错误:无法使用“in”运算符在未定义中搜索“值”

解决方案:将其内联用作

$.fn.editable.defaults.mode = '内联';

于 2015-08-25T12:03:15.087 回答