Skip to content

Instantly share code, notes, and snippets.

@stakes
Created August 28, 2014 01:27
Show Gist options
  • Save stakes/82b1a6ec682aaa973569 to your computer and use it in GitHub Desktop.
Save stakes/82b1a6ec682aaa973569 to your computer and use it in GitHub Desktop.
ActiveAdmin.register Collection do
permit_params do
permitted = [
:id,
:abstract,
:publish_date,
:vertical_id,
articles_attributes: [
:collection,
:title,
:excerpt,
:content,
:dek,
:image_url,
:publish_date,
:word_count,
:url,
:short_url,
:author,
:domain,
:found_at_url,
:total_pages,
:collection_id,
:position,
:reading_time,
:id,
:_destroy
]
]
end
index do
selectable_column
column 'Date', :publish_date
column 'Articles' do |collection|
collection.articles.count
end
actions
end
action_item only: :show do
link_to 'Update campaign', update_campaign_admin_collection_path
end
show do |collection|
attributes_table do
row :publish_date
collection.articles.each do |article|
row :article do
article.title
end
end
row :abstract
end
active_admin_comments
end
form do |f|
f.inputs 'Vertical' do
f.input :vertical
end
f.inputs 'Publish date' do
f.input :publish_date, label: 'Publish Collection At', as: :datepicker, datepicker_options: { min_date: Date.today.to_date }
end
f.inputs do
f.has_many :articles, heading: 'Articles', allow_destroy: true, sortable: :position, new_record: 'Add another article' do |t|
t.input :url
end
end
f.inputs 'Abstract' do
f.input :abstract
end
f.actions
end
member_action :update_campaign, method: :get do
# TODO: check if the call is successful or not and handle appropriately
resource.update_campaign
redirect_to 'admin/collections#index'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment