Search code examples
ruby-on-railsactiveadminformtastic

How to display links with one-to-many relationships using Formtastic and ActiveAdmin


I have a one-to-many relationship (Stories have many Surveys). How can I cause the "index" and "show" pages to display links to Surveys rather than text (as they currently display)?

ActiveAdmin.register Story do
  actions :all

  form do |f|
    f.inputs
    f.buttons
  end

  index do
    column :surveys
    default_actions
  end

  show do
    attributes_table do
      row :surveys
    end
    active_admin_comments
  end

Solution

  • You could do something like this:

    ...
    column 'Surveys' do |story|
      story.surveys.map { |survey|
        link_to survey.name, admin_survey_path(survey)
      }.join("<br/>").html_safe
    end
    
    ...
    row 'Surveys' do |story|
      story.surveys.map { |survey| 
        link_to survey.name, admin_survey_path(survey)
      }.join("<br/>").html_safe
    end