如何在ActiveAdmin的显示页面上的Div下添加link_to Rails 4

时间:2015-06-16 05:31:50

标签: ruby-on-rails ruby activeadmin show

我已经实现了一个Active Admin的显示页面。在此面板中,我按loop显示数据列表。这是我做的:

 show do
  default_main_content
  panel "Best #{trip_type.camelize} (Live)" do
    live_datas1.each do |live|
      div do
        live["outbound_date"].strftime('%A')+ ", " + live["outbound_date"].strftime('%Y-%m-%d') + " To " + live["inbound_date"].strftime('%A') + ", " + live["inbound_date"].strftime('%Y-%m-%d') + " = " + flight.currency_symbol + live["price"] 
      end
    end
  end
 end

这给了我输出:

Best Shortbreak (Live)
Monday, 2015-08-10 To Wednesday, 2015-08-12 = £716.0
Monday, 2015-08-03 To Wednesday, 2015-08-05 = £761.0
Wednesday, 2015-08-12 To Friday, 2015-08-14 = £806.0
Wednesday, 2015-08-19 To Friday, 2015-08-21 = £876.0

现在我想在该行的每一端添加一个链接:

Monday, 2015-08-10 To Wednesday, 2015-08-12 = £716.0 [Link]

为此我添加

live["outbound_date"].strftime('%A')+ ", " + live["outbound_date"].strftime('%Y-%m-%d') + " To " + live["inbound_date"].strftime('%A') + ", " + live["inbound_date"].strftime('%Y-%m-%d') + " = " + flight.currency_symbol + live["price"] + link_to "Link", "#"

还尝试将link_to放入下一行。但在这种情况下,上面的内容不会只显示链接。

我错了。你能指点我吗? 我已经引用了这个http://activeadmin.info/docs/6-show-pages.html但没有得到任何解决方案。

1 个答案:

答案 0 :(得分:2)

您可以编写以下代码,它可以正常工作。

show do  
  default_main_content  
  panel "Best #{trip_type.camelize} (Live)" do  
    live_datas1.each do |live|  
      div do
        "#{live["outbound_date"].strftime('%A')}, #{live["outbound_date"].strftime('%Y-%m-%d')} To #{live["inbound_date"].strftime('%A')}, #{live["inbound_date"].strftime('%Y-%m-%d')} = #{flight.currency_symbol}#{live["price"]} [#{link_to "Link", "#"}]".html_safe
      end
    end  
  end
end