【问题标题】:Using Best In Place gem, how do I allow links to be edited in place?使用 Best In Place gem,我如何允许就地编辑链接?
【发布时间】:2012-10-28 01:11:26
【问题描述】:

我有一个名为“item”的对象,它有一个可以链接到任何 URL 的“title”。我使用以下代码允许使用 Best in Place gem 就地编辑标题。编辑部分工作正常,但是当从输入框中移除焦点时,链接丢失。

         <%= best_in_place item, :title, 
                              :display_with => :link_to, 
                              :activator => "#edit-#{item.id}",
                              :helper_options => item.url  %>

我感觉我没有正确设置“helper_options”的值。

如何编辑上面的代码,以便在用户更改标题后使用更新的文本恢复链接?我在Best in Place github site 或其他任何地方都找不到这样的例子。

【问题讨论】:

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


    【解决方案1】:

    迟到的答案,但你永远不知道谁会是类似的东西?对于你的情况,我认为你想要一个块:

    <%= link_to(item.url) do %>
       <span><%= best_in_place item, :title, 
         :activator => "#edit-#{item.id}" %>
       </span> 
    <% end %>
    

    这假设您要编辑标题,而不是链接的 URL。

    要编辑链接但使用标题作为链接正文,您可以在 display_with 中使用 lambda

    = best_in_place item, 
      :url, 
      :display_with => lambda { 
        |url| link_to item.title, url
      }
    

    那是 haml,我没有测试确切的片段,但在我正在构建的应用程序中也有类似的工作

    【讨论】:

      猜你喜欢
      • 2012-05-16
      • 1970-01-01
      • 2013-01-25
      • 1970-01-01
      • 2013-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多