Skip to content

Instantly share code, notes, and snippets.

View kivanio's full-sized avatar
🏠
Working from home

Kivanio Barbosa kivanio

🏠
Working from home
View GitHub Profile
class ApplicationController < ActionController::API
include AbstractController::Translation
include ActionController::MimeResponds
include ActionController::ImplicitRender
include ActionController::StrongParameters
# Gems that tries to include something in ActionController::Base
include JSend::Rails::Controller
include CanCan::ControllerAdditions
class Ability
include CanCan::Ability
attr_reader :current_user
def initialize(user)
alias_action :create, :update, :destroy, :to => :write
@current_user = user || User.new
# Add this code to a new file and you can put it under app/admin/lib folder or else config/initializer/actice_admin.rb
module ActiveAdmin
module Views
class TableFor
def html_column(attribute)
column(attribute){ |model| model[attribute].html_safe }
end
def bool_column(attribute)
# config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
config.current_user_method = :current_user
config.authentication_method = :authenticate_user!
config.before_filter :admin_role_filter
end
# Adding all recource names to Permissions table after ActiveAdmin is loaded
ActiveAdmin.register AdvocacyPage do
menu label: 'Advocacy Page', url: "/admin/advocacy_pages/edit"
breadcrumb { [] }
permit_params :heading, :description
actions :update
controller do
def resource
@kivanio
kivanio / Gemfile
Last active August 29, 2015 14:16 — forked from tylerhunt/Gemfile
gem 'active_model_serializers'
gem 'activeadmin'
gem 'jquery-ui-rails'
@kivanio
kivanio / products.rb
Last active August 29, 2015 14:16 — forked from gregbell/products.rb
ActiveAdmin.register Product do
# Will show the default main content...
show do
# Do stuff before
default_main_content
# Do stuff after
end
# ... Or if you want to customize further
@kivanio
kivanio / article.rb
Last active August 29, 2015 14:16 — forked from amolpujari/article.rb
ActiveAdmin.register Article do
index do
selectable_column
id_column
column :name, :sortable => :name do |resource|
editable_text_column resource, :name
end
column 'Type', :sortable => :article_type do |resource|
column_select(resource, :article_type, ["News", "Story", "Case Study", "Business"])
end
# http://stackoverflow.com/a/8936202
#
# ActiveAdmin already includes the necessary jquery in active_admin/base,
# so just add this to javascripts/active_admin.js after //= require active_admin/base
#
#
# Serialize and Sort
#
# model_name - you guessed it, the name of the model we are calling sort on.
# This is the actual variable name, no need to change it.
ActiveAdmin.register CityNeighbourhood do
member_action :change_neighbourhoods, :method => :get do
@neighbourhoods = City.find_by_id(params[:city_id]).try(:neighbourhoods)
render :text => view_context.options_from_collection_for_select(@neighbourhoods, :id, :name)
end
#...
form do |f|
f.input :city, input_html: {
onchange: remote_get("change_neighbourhoods", 'city_id', :neighbourhood_id)
}