Skip to content

Instantly share code, notes, and snippets.

@ChrisSki
Last active December 21, 2015 13:39
Show Gist options
  • Save ChrisSki/6314060 to your computer and use it in GitHub Desktop.
Save ChrisSki/6314060 to your computer and use it in GitHub Desktop.
Associations
ActiveAdmin.register State do
index do
column :name
column "Associated Towns" do |state|
ul do
state.towns.each do |town|
li link_to(town.name, admin_town_path(town))
end
end
end
end
controller do
def permitted_params
params.permit state: :name
end
end
end
ActiveAdmin.register Town do
index do
column :name
column "State" do |town|
town.state.each do |state|
link_to(state.name, admin_state_path(state))
end
end
end
controller do
def permitted_params
params.permit town: [:name, :state_id]
end
end
end
@genericsteele
Copy link

Because towns only have one state, you don't need the loop from lines 6-8 in town.rb

Should just be able to call town.state.name instead of town.state.each ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment