how do add a link to an ActiveAdmin view

▼魔方 西西 提交于 2019-12-18 12:25:17

问题


I have:

ActiveAdmin.register User do
  show :title => :name do     
    attributes_table do
      row :username
      row :email
      row :last_request_at
      row :foo
    end
  end
end

and I want foo just make a <a href="/foo">foo</a> in the view.

So I define:

def foo
  <a href="/foo">foo</a>
end

in the user.rb model. And it displays but the tag is escaped so it's not clickable. Is there a simple way to do this?


回答1:


You can try:

row :foo do
  link_to('foo','#')
end

and replace '#' with your route.




回答2:


if you are working with a has many you can loop through the list as well, important is not too forget the .html_safe

row "Bars" do |foo|
  foo.bars.each.map do |bar|
    link_to(bar.title, admin_bar_path(bar)) 
  end.join(', ').html_safe
end



回答3:


= link_to 'List Users', admin_users_path in your view should work. Check that your ActiveAdmin namespace is actually admin using ActiveAdmin.application.default_namespace.to_s (in the console) though.

Hope that helps someone.



来源:https://stackoverflow.com/questions/15799566/how-do-add-a-link-to-an-activeadmin-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!