activeadmin

Rails Rake Task drop table and import from csv

旧街凉风 提交于 2019-12-23 05:25:20
问题 I am trying to write a rake task to drop a table and repopulate it from a csv. The intention is to obtain the data from another system on a schedule, and use a button in the admin interface of my rails application to import the new data. This new data will overwrite the old data in the table. I am not exactly sure how to do this so am playing around with rake tasks. So far I can import the new data but I can't figure out how to drop the table first. My code so far is: namespace

How to ignore case when sorting a column

扶醉桌前 提交于 2019-12-23 04:54:09
问题 When I sort the name column of a model in ActiveAdmin , I get output such as the following: Apples Icicles Zebras iMacs iPhones where the uppercase and lowercase letters appear to be sorted separately. I prefer to display sorted columns in the following manner: Apples Icicles iMacs iPhones Zebras with no unnatural case sensitivity. I tried using the line column :name, sortable: 'my_model.name.downcase' to mitigate the issue, but this throws an ActiveRecord::StatementInvalid error. How can I

ActiveAdmin Collection action on filtered data

江枫思渺然 提交于 2019-12-22 11:22:30
问题 I have a custom collection action on the index page, and I want to access the filtered data inside that action. How can I do this? Can I get the collection itself? or maybe the filter params? collection_action :do_something do # call some async process redirect_to :action => :index, :notice => "started working!" end action_item :only => :index do link_to('DO WORK', do_something_admin_game_stats_path) end 回答1: You should pass the scope and filter params as options on your link_to action, and

NoMethodError undefined method `link_to_function'

流过昼夜 提交于 2019-12-22 08:15:55
问题 I added ActiveAdmin to my app, updated some gems and now I get a undefined method `link_to_function' when viewing users show page. I have the will_paginate gem and I added a initializer so there's no conflict. kaminari.rb: Kaminari.configure do |config| config.page_method_name = :per_page_kaminari end The error points to the line on from /app/helpers/will_paginate_helper.rb: @template.link_to_function(text.to_s.html_safe, ajax_call, attributes) 回答1: Add a helper method and it will fix your

ActiveAdmin - uninitialized constant AdminUser

人盡茶涼 提交于 2019-12-22 06:09:51
问题 I'm getting an error while trying to run my app, having recently installed ActiveAdmin. It was working fine, but, after idling for a while, suddenly it isn't! In my gem file: gem 'activeadmin' In my routes: devise_for :admin_users, ActiveAdmin::Devise.config ActiveAdmin.routes(self) And in my admin_user.rb ActiveAdmin.register AdminUser do index do column :email column :current_sign_in_at column :last_sign_in_at column :sign_in_count default_actions end etc.... The error when trying to run:

ActiveAdmin won't save has many and belongs to many field

浪尽此生 提交于 2019-12-22 04:37:13
问题 I have 2 models. Category and Post. They are connected using a has_many_and_belongs_to_many relationship. I checked in the rails console and the relationship works. I created checkboxes in activeadmin to set the post categories using this form field: f.input :categories, as: :check_boxes, collection: Category.all The problem is when I try to save it because every other field data (title, body, meta infos etc.) is saved, but the category stays the same even if I unchecked it, or checked

ActiveAdmin actions

做~自己de王妃 提交于 2019-12-22 01:34:03
问题 is there a way to specify in ActiveAdmin's index page of a model what actions are allowed, things like: index do actions :edit end index do actions only: :edit end do not work. What's the correct syntax? Appreciated. bundle show activeadmin /home/muichkine/.rvm/gems/ruby-2.1.2/bundler/gems/active_admin-9cfc45330e5a 回答1: Add whatever actions you want to be available by using actions (it is usually put under model definition): ActiveAdmin.register YourModel do actions :index, :show, :create,

Rails 3 ActiveAdmin. How to set a default sort order for an associated record?

爷,独闯天下 提交于 2019-12-21 20:18:19
问题 I have a shipments model and an invoice model. The invoice belongs to shipment. So I added a default sort order for shipment like this... config.sort_order = 'file_number_desc' But now I want to add the same sort order for invoices, (shipments table is the one that has the file_number column) but this doesn't seem to work: config.sort_order = 'shipments.file_number_desc' 回答1: Nice solution @Siwei, I would just use, instead of the scope :joined which by default shows a filter on top of the

undefined method `has_many' for Formtastic

你。 提交于 2019-12-21 12:59:48
问题 I'm getting this error : undefined method `has_many' for #<Formtastic::SemanticFormBuilder:0xb410d4c> It work when I use it like this : ActiveAdmin.register Ressource do form do |f| f.inputs do f.input :offer_id, :as => :hidden f.input :name f.input :category, :include_blank => false, :collection => Category.order('place ASC').all, :member_label => :to_label f.input :description, :input_html => {:class => 'editor'} f.input :price end f.has_many :roles do |app_f| app_f.inputs do if not app_f

Customizing the show page in ActiveAdmin

五迷三道 提交于 2019-12-21 04:13:37
问题 The default show page in ActiveAdmin is a table with one attribute per row. For my backend, this would be fine, except that I want to hide fields such as id, created_at, updated_at. Is is possible to do that in a way similar to the index page, i.e. by explicitly listing the desired attributes, while letting AtiveAdmin handle the layout? The only example shown in the docs suggests that to customize the show page you have to completely take over and write a partial or an arbre construct. Thanks