【问题标题】:How to use Best in place with nested association in ruby on rails如何在 ruby​​ on rails 中使用 Best in place 和嵌套关联
【发布时间】:2016-03-04 10:31:44
【问题描述】:

app/models/user.rb

has_one :user_detail

app/models/user_detail.rb

belongs_to :user

unit_number 是 user_detail 的属性。

我想在用户显示页面中编辑内联这个属性。但我不明白我是怎么做的。

<%= best_in_place user, :unit_number %>

它给出了一个错误。我是怎么做的?

【问题讨论】:

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


    【解决方案1】:

    请试试这个:

    <%= best_in_place user.user_detail, :unit_number, path: user_detail_path %>
    

    其中user_detail_path 是更新用户详细信息路径。您必须从 routes.rb 定义此路由。

    【讨论】:

    • 这里有一个如果 user.user_detail 为 nil 则它给出错误...我希望如果 user.user_detail 为 nil 则显示 0 并且用户可以编辑它?可能吗?跨度>
    • 未定义方法 `user_detail_path' 用于 #:0x007fa21523e420>
    • user_details资源有配置吗?
    • 有user_details控制器吗?
    • No as such no controller
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-16
    • 2013-01-25
    • 1970-01-01
    • 1970-01-01
    • 2013-06-21
    • 1970-01-01
    相关资源
    最近更新 更多