Created
February 8, 2018 17:59
-
-
Save grillermo/3570369b12e6b4587672f33fc84a8662 to your computer and use it in GitHub Desktop.
A complete rails admin custom action, the file of this gist are the paths were you should put your files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alert('omg hi!') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.create_aliada_working_hours | |
background: grey |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you use can can for your admin you'll have to add in your admin ability | |
can :create_aliada_working_hours |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.create_aliada_working_hours | |
Lets do some cool stuff! | |
= javascript_include_tag 'rails_admin/actions/create_aliada_working_hours' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Register actions at the top of the file | |
RailsAdmin::Config::Actions.register(:create_aliada_working_hours, RailsAdmin::Config::Actions::CreateAliadaWorkingHours) | |
# Inside the actions block | |
config.actions do | |
create_aliada_working_hours do | |
visible do | |
bindings[:abstract_model].model.to_s == 'Aliada' | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
en: | |
admin: | |
actions: | |
create_aliada_working_hours: | |
title: Create aliada working hours | |
menu: Create aliada working hours | |
breadcrumb: Create aliada working hours |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding : utf-8 -*- | |
require 'rails_admin/config/actions' | |
require 'rails_admin/config/actions/base' | |
module RailsAdmin | |
module Config | |
module Actions | |
class CreateAliadaWorkingHours < RailsAdmin::Config::Actions::Base | |
RailsAdmin::Config::Actions.register(self) | |
register_instance_option :member? do | |
true | |
end | |
register_instance_option :http_methods do | |
[:get, :post] | |
end | |
register_instance_option :link_icon do | |
# Escoger uno bonito de http://getbootstrap.com/2.3.2/base-css.html#icons | |
'icon-time' | |
end | |
# Might cause random bugs if enabled | |
register_instance_option :pjax? do | |
false | |
end | |
register_instance_option :controller do | |
Proc.new do | |
next render :action => @action.template_name if !request.post? | |
aliada_id = params[:id] | |
if AliadaWorkingHour.update_from_admin(aliada_id: aliada_id) | |
redirect_to back_or_index | |
else | |
render json: {status: :success, url: rails_admin.create_aliada_working_hours_path} | |
end | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment