【问题标题】:How to custom actions method helper in active admin如何在活动管理员中自定义操作方法帮助程序
【发布时间】:2016-04-27 07:42:15
【问题描述】:

当我定义时

  index do
    column :id, :sortable => :id
    column :title
    column :avatar do |post|
      div style: "text-align:center;" do 
        image_tag post.avatar_url(:thumb), :class => "img-responsive"
      end 
    end
    column :published
    actions
  end 

“操作”一般 3 个链接(查看、编辑和删除) 我想为上面的 3 个链接添加 target="_parent"。

示例:

<a class="edit_link member_link" href="/admin/places/5/edit?locale=en">Edit</a>

<a class="edit_link member_link" href="/admin/places/5/edit?locale=en" target="_parent">Edit</a>

如何做到这一点?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 rubygems activeadmin


    【解决方案1】:

    要设置查看、编辑和删除资源的链接,请使用操作方法:

    index do
      selectable_column
      column :title
      actions
    end
    

    您还可以将自定义链接附加到默认链接:

    index do
      selectable_column
      column :title
      actions do |post|
        link_to "Preview", admin_preview_post_path(post), class: "member_link"
      end
    end
    

    或者完全放弃默认链接:

    index do
      column :title
      actions defaults: false do |post|
        link_to "View", admin_post_path(post)
      end
    end
    

    如果您更喜欢在下拉菜单中列出操作链接:

    index do
      selectable_column
      column :title
      actions dropdown: true do |post|
        item "Preview", admin_preview_post_path(post)
      end
    end
    

    参考:http://activeadmin.info/docs/3-index-pages/index-as-table.html#defining-columns

    【讨论】:

    • tks,我想在新对象的链接中添加target='_parent'。如何做到这一点?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多