FAQ Database Discussion Community


How to add link_to under Div on ActiveAdmin's show page | Rails 4

ruby-on-rails,ruby,activeadmin,show
I have implemented one panel of Active Admin's show page. In this panel I am showing list of data by loop. Here is what I did: show do default_main_content panel "Best #{trip_type.camelize} (Live)" do live_datas1.each do |live| div do live["outbound_date"].strftime('%A')+ ", " + live["outbound_date"].strftime('%Y-%m-%d') + " To " + live["inbound_date"].strftime('%A')...

active admin: undefined method `name' for nil:NilClass

ruby-on-rails,ruby,activeadmin
I am having a problem with active admin. I am getting the following issue, undefined method `name' for nil:NilClass around the line insert_tag renderer_for(:index) I googled for the issue. Some suggested to pull the activeadmin from master branch. I tried it too. I updated the gemfile as: gem 'activeadmin', github:...

How can ActiveAdmin start sorting columns after the first click on columns' header in ascending order?

ruby-on-rails,activeadmin
By default ActiveAdmin seems to sort all the columns in index pages (after the user click on header's column) in descending order. Is it possible to specify the initial direction of sorting for all columns? Note: I'm not referring to the config.sort_order which only creates the default order for when...

Rails+ActiveAdmin with custom user`s model (without Devise):

ruby-on-rails,ruby,ruby-on-rails-4,activeadmin
I am using ActiveAdmin with custom User model (without Devise) and custom SessionsController. I successfully installed ActiveAdmin, implement the necessary methods, but faced a problem: after the first visit dashboard, the user`s remember_token removed from the cookies (I found it in a browser) that leads to the log out user...

How to precompile assets with activeadmin

ruby-on-rails,activerecord,heroku,activeadmin
I have these lines in my production.rb config.serve_static_assets = false config.assets.js_compressor = :uglifier config.assets.compile = true config.assets.precompile += ['active_admin.js', 'active_admin.css', 'active_admin/print.css'] and my application.rb file has this line config.assets.precompile = %w(*) but when I try to update my assets with git rm -rf public/assets rake assets:precompile I get this error...

How to limit number of filtered results in ActiveAdmin

ruby-on-rails,activeadmin
I'm running Active Admin 1.0.0 on Rails 4.2 and I have a resource named Contact. Amongst others there is a field called score. I would like to use the built in filter functionality on the Contact index page to allow a user to search for the Contacts with the top...

ActiveAdmin formtastic link_to on a collection leading to the show view

ruby-on-rails-4,collections,activeadmin,formtastic,link-to
Just wondering about how to have this link to this to the appropriate supplier_company_view with clickable names. The .to_sentence is optional. column :supply_companies do |pt| pt.supply_companies.collect {|c| c.company_name.capitalize }.to_sentence end ...

Active Admin refactoring

ruby-on-rails,activeadmin
I am currently creating a dashboard in Active Admin for my product orders (and associated models). I want to show data from multiple models within this table, and as a result the table is horribly repetitive. I am not very good with Active Admin and would love some advice on...

Custom ActiveAdmin Scope to display books without a tag

ruby,ruby-on-rails-4,scope,tags,activeadmin
I am using ActiveAdmin in my rails app. Everything works great, but now I am trying to create a scope that will display books without a tag. I have created a method in my Book model to help me do this, but I cannot use it inside my ActiveAdmin scope....

Disable the auto generated dropdown for belongs_to relations in Rails/ActiveAdmin

ruby-on-rails,activeadmin
I have two models: UserDevice and UserInfo as follows (in schema.rb): create_table "user_devices", force: :cascade do |t| t.integer "user_info_id" t.string "platform" t.string "unique_id" t.string "id_for_push" t.string "last_ip" t.string "unique_id_type" t.datetime "created_at", null: false t.datetime "updated_at", null: false end add_index "user_devices", ["user_info_id"], name: "index_user_devices_on_user_info_id", using: :btree create_table "user_infos", force: :cascade do...

How to add a report/custom page to ActiveAdmin?

ruby-on-rails,ruby,activeadmin
I am using ActiveAdmin for my Ruby on Rails application. My model consists of a couple entites such as "Plan", "Country", etc. I would like to have custom page for reporting purposes. This page should work on a collection of selected plans. So, I need scopes and filters. Currently one...

How to send form with ajax post request with rails

jquery,ruby-on-rails,ajax,activeadmin
I want to send whole form inputs using ajax with a post request. I'm using this code of js : $.post('#{my_custom_action_path}', $('#myform').serialize(), function(data) { console.log("Success !") }); The problem is that the form is generated by rails with a "_method" input containing "patch" This result of using the wrong route...

How would you add Active Admin index columns from a sibling table?

ruby-on-rails-3,activeadmin
In my Customers_Rewards active admin I currently display columns from the Customer_Rewards and Customer data table, but I also want to display columns (such as store_id) from the Order data table. ActiveAdmin.register CustomerReward do menu :parent=>"Customers", :priority=>10, :label=>"Activated Rewards" index do selectable_column column("Customer ID"){|u| u.customer.id } column("Store ID"){|u| u.order.store_id }...

ActiveAdmin Papperclip Show multiple images in Index and show

ruby-on-rails-4,paperclip,activeadmin,nested-forms
Hi just a quick Question on showing multiple images on the index-page and show page. My images are stored fine in a product_images table with a product_id as the foreign key. Just going around in circles now on this. I've tried to play with similar code to no avail. row...

how to edit menu bar in active admin? - change the language. Rails

ruby-on-rails-4,activeadmin
I'm using Active Admin with i18n. Everything works but if i want to change language I need to do that by hand - changing site address :-(... How to add buttons in navigate bar with models names? It could be another place but good for that - accessible.

Execute controller action from ActiveAdmin panel using link_to

ruby-on-rails,methods,activeadmin
I have Rails 4 and ActiveAdmin plugin. In advertisement controller I have 3 methods. Bassicaly I want to add admin function to extend advertisement expire date. There are three options: def add_two_weeks(advertisement) @advertisement = advertisement @advertisement.expiration = @advertisement.expiration + 14.days @advertisement.save end def add_eight_weeks(advertisement) @advertisement = advertisement @advertisement.expiration = @advertisement.expiration...

ActiveAdmin: routes for overridden controllers

ruby-on-rails,ruby-on-rails-4,devise,activeadmin
I want to override login for activeadmin. I created SessionsController and override create action like class Admin::SessionsController < ActiveAdmin::Devise::SessionsController def create session[:zzz] = 1 logger.debug("@@@ #{session[:zzz]}") super end end How should I apply the changes for activeadmin devise controller? for devise I would make it like devise_for :users, controllers: {sessions:...

Empty field in Activeadmin resource

ruby-on-rails-4,activeadmin
I'm using gem 'activeadmin' in my project. here is app\admin\person.rb file ActiveAdmin.register Person do permit_params :name, :gender, :age, :address show do attributes_table do row :image do image_tag(person.image.url) end row :name row :gender row :age row :address end end end how can I stop showing empty field in Activeadmin resource view....

ActiveAdmin Devise Cancancan and Three User Models — infinite loop

ruby-on-rails-4,devise,activeadmin,infinite-loop,cancancan
I'm currently running three user models. Staff, customers and suppliers. Each has a devise model and I can seem to nail how to authorize only Staff to get to the activeadmin pages. I have managed to get one Model to access it but then the other two go into a...

Multi nested attributes with ActiveAdmin

ruby-on-rails,activeadmin,nested-forms,nested-attributes
Hey so I have three models: DataSet BrowseOption BrowseOptionData Similar to Ryan's railscasts (http://railscasts.com/episodes/196-nested-model-form-revised?view=comments) I want to have a double nested form except in ActiveAdmin. Here is my Active Admin form: form do |f| f.inputs "Data Set Info" do f.input :name f.input :display_name f.input :description f.input :cover_photo, :label => "Cover...

Nested attributes in form not visible

ruby-on-rails,activeadmin,nested-attributes,formtastic
I'm likely missing something simple, but I've tried a number of things to no avail. I need to be able to edit an existing track (using ActiveAdmin) and save the record updating its exclusivity status. I have a Tracks model #app/models/track.rb: has_many :exclusivities, class_name: 'Exclusivity', dependent: :destroy accepts_nested_attributes_for :exclusivities attr_accessible...

how to add sorted elements in the filter dropdown in activeadmin rails

ruby-on-rails,activeadmin
I have a Post model, PostSource model. A PostSource has many posts, a post belong to one PostSource. Using ActiveAdmin, in the Index action of the Post, I am displaying a filter of PostSource this way: filter :post_source, label: 'Source' filter :category, as: :select, collection: Category.order(:name).collect { |cat| [cat.name, cat.id]...

ActiveAdmin add current admin as author

ruby-on-rails,ruby,activeadmin
I've got a pretty simple Post model I'm exposing through ActiveAdmin. Is it possible to attribute a Post on create to an author (the current ActiveAdmin user)? In a regular controller I'd just use: @post = Post.new(params[:post]) @post.author = user @post.save ...

ActiveAdmin form validation before save

ruby-on-rails-4,activeadmin
I have form fields from one model status_history that I am including in my member edit. I am wanting to make it so that if the fields for status_history are empty, then it will not save. Currently it is saving blank items to status_history when I save a members edit....

Build association while initializing to satisfy delegates

ruby-on-rails,activerecord,delegates,associations,activeadmin
I have this minimal example model: class Book < ActiveRecord::Base belongs_to :author delegate :name, prefix: true, to: author after_initialize { author ||= Author.new } end After posting form data my framework (yes, ActiveAdmin) does this: Book.new {author_name: 'Some Dude'} which results in author_name not being written since the after_initialize callback...

Formatting issue in ActiveAdmin dashboard

ruby-on-rails,ruby,rubygems,activeadmin
I'm having an issue pulling the correct information into a dashboard column using ActiveAdmin. If anyone could help me wrap my head around this issue it would be greatly appreciated. The issue I'm having is retaining the data from an associated class with the current record I'm displaying (line 6...

How to specify eager loading globally for a resource in ActiveAdmin 0.5.0?

ruby-on-rails,ruby,activeadmin
I have a page registered to a model in my ActiveAdmin application as follows: ActiveAdmin.register Report do menu parent: 'Administration', priority: 2 scope ... scope ... filter ... filter ... end The "Report" model/resource has a number of associations with other models. What is the best way to specify eager...

Rails - incorrect google static map - lat long correct for given address -Active Admin - image_tag

ruby-on-rails,google-maps,activeadmin,google-static-maps
ActiveAdmin Rails 4 Google Static map issue The code below shows the correct lat and long for the give addresses but when used in googlemap static map it show the completely incorrect map. Any reason you can think of? If I manually place the lat and long into the http:...

ActiveAdmin ::Show 4 textbox in active admin using has_many relationship

ruby-on-rails,gem,activeadmin
I have one poll table having with question filed and each question have 4 answer which is has_many relation ship with answer table class Poll < ActiveRecord::Base has_many :answer end My answer model class Answer < ActiveRecord::Base belongs_to :poll, :class_name => "Poll", :foreign_key => "question_id" end My active admin form...

Rails 4 activeadmin 1.0.0pre uninitialized constant on application.rb

ruby-on-rails-4,activeadmin
I am getting an uninitialized constant after bundle installing the activeadmin gem from master. I can run my app just fine on a different branch without activeadmin. Gemfile: gem 'activeadmin', github: 'activeadmin' Stacktrace: /Users/nhamidjaja/dev/rails/bourbon/config/application.rb:10:in `<module:Bourbon>': uninitialized constant Bourbon::Rails::Application (NameError) from /Users/nhamidjaja/dev/rails/bourbon/config/application.rb:9:in `<top (required)>' from...

Organize lecture with chapter and lesson models

ruby-on-rails,ruby-on-rails-4,activeadmin
I am trying to organize my models so that I get to see in lecture.rb > chapter.rb > lesson.rb. As you can imagine chapter.rb have to be organized by order in the view as well as the nested lesson within chapters. It is a bit confusing.. My idea so far...

Switching language (locale) in ActiveAdmin without passing a parameter

ruby-on-rails-4,locale,activeadmin,rails-i18n
I want to be able to switch my locale in an ActiveAdmin app of mine. So far I've followed this guide on switching-locale, which actually mentions the problem I'm having: You will notice, however, that all links keep the default locale of your app. So in my case, once I...

Active Admin - Dropdown menu with same resources

ruby-on-rails,activeadmin
I have a picture model and I want to know if it is possible for me to create a drop down menu where both resources are pictures with different names. My picture model has an attribute 'gender', which can either be male or female. I want to create the following...

ActiveAdmin Nested Form multiple select

ruby-on-rails-4,activeadmin,nested-forms
I'm trying to get the product_suppliers to update via the product form. The form displays all suppliers in the supplier table but it doesn't update the join table. Not sure where the error lies. Index and show show correct details but edit is not updating the join table. Starting to...

How to use Rails' simple_format with special characters?

ruby-on-rails,ruby,activeadmin,arbre
On Rails 3.2.13, simple_format does not return what I expect it to do, on an admittedly convoluted case: > simple_format("a <= 2, b < 4") "<p>a &lt; 4</p>" Since this case does not seem to work properly (I'm losing half my string!), is there a way to pre-escape special characters...

Blocking batch_actions with ActiveAdmin and CanCan

ruby-on-rails,authorization,activeadmin,cancan
I am using ActiveAdmin with Cancan for authorization. In my ability model, I setup a user to only have read ability. This works as expected, except the user can still select devices(the model I am restricting) and then perform a batch_update to edit one or more of them. I can't...

Active admin not finding partial in show

ruby-on-rails,ruby-on-rails-4,activeadmin
This should be pretty simple, trying to render a partial on active admin in show action: Object name is: Listing ActiveAdmin.register Listing do show do attributes_table do row :foo row :bar render 'map' end end end I added the partial under app/admin/listings/_map.html.haml I get the no template found error: Missing...

Can't create new record in Active Admin panel, Rails 4 and Devise

ruby-on-rails,ruby-on-rails-3,devise,imagemagick,activeadmin
I have created ActiveAdmin controlpanel for my app. Problem is that I can't create new advertisement from there. Any other resource I can create without problems. admin/advertisement.rb form :html => { :enctype => "multipart/form-data" } do |f| f.inputs "Content" do f.input :name f.input :email f.input :country f.input :phone_number f.input :region...

Activeadmin where to place this variable code from my view

variables,ruby-on-rails-4,controller,activeadmin
I have created a nice little view but it has some code in it that I would normally place in a controller. I have tried making a controller for the model but Active Admin ignores it. I have tried a small controller do block inside the Active Admin resource file...

ActiveAdmin “f.inputs, except: [:field]” doesn't work

ruby-on-rails,activeadmin,formtastic
Formtastic has a great tool to prevent certain fields on a model showing up, used as so: f.inputs, :except => [:featured, :something_for_admin_only] ActiveAdmin claims to be derived from Formtastic, but it seems that ":except" doesn't work. Any idea why?...

How To Make ActiveAdmin Load Particular Data For Index

ruby-on-rails,activeadmin
This is what i want. I have table called some x and i added this table in Active Admin Page. What happens after i added it load all the data in that table for index page. But i want to load only data that are true for some condition. Say...

How to insert hint information right after the input box?

ruby-on-rails,activeadmin
Not really an issue but some question that I need Is it possible to attached html values right after the input box? Something like a small text info below the input box I have did something similar but its not pretty. f.inputs "Blog" do f.input :view_counts, :input_html => { :readonly...

Rails + ActiveAdmin: no success with custom instance variables

ruby-on-rails,ruby,controller,activeadmin,instance-variables
I'm trying to use the controller method in ActiveAdmin to no avail. # ActiveAdmin.register Job do controller do def show @job = Job.find(params[:id]) @psr = @job.psr end end ... show do |job| attributes_table_for @psr do row :created_at end end The above results in a NilClass error on @psr. What am...

Matrix Edit in rails ActiveAdmin?

ruby-on-rails-4,activeadmin
I'm using ActiveAdmin in Rails. My use case is similar to currency-exchange: say I have 10 currencies, and one currency can be converted into another one. In order to support editing, I need to create a matrix, where rows is CurrencyA, and columns is CurrencyB, and the value is conversion...

ActiveAdmin path links_to rendering raw html

ruby-on-rails,ruby-on-rails-4,activeadmin
While on the Dashboard, I'm trying to hyperlink data points to their Edit page using the following code DataPoint.limit(15).order("created_at desc").map do |post| li link_to(post.data_type.study.name.to_s, admin_studies_path(post)) if post.numerical_value.present? div "Number: " + link_to(post.numerical_value.to_s, admin_data_point_path(post)) end However what happens is the raw html is rendered on the page, even though I tried...

How to prevent automatic rollback when trying to set user as admin

ruby-on-rails,activeadmin,rollback
Hi Active admin is installed on my app; I am trying to set up a new user as admin using rails console. I am selecting a specific user in my table user. Then writting user.admin = true then user.save but then (0.2ms) BEGIN (0.3ms) ROLLBACK => false I have an...

rails g active_admin:install ERROR

ruby-on-rails,ruby,activeadmin
I have problem with ActiveAdmin. I've added the gem 'activeadmin' to my Gemfile and ran $ bundle install which worked. But when I try to: $ rails g active_admin:install I get: /home/dominika/active_admin/config/application.rb:10:in `<module:ActiveAdmin>': superclass mismatch for class Application (TypeError) from /home/dominika/active_admin/config/application.rb:9:in `<top (required)>' from /home/dominika/.rvm/gems/ruby-2.2.0/gems/spring-1.2.0/lib/spring/application.rb:82:in `require' from...

In ActiveAdmin, is there a way to display associated nil model?

ruby-on-rails,activeadmin
I have a model Site which includes a foreign key to User, user_id. All of the sites have a user_id but over time, some of the referenced User elements have been deleted. My ActiveAdmin index looks like this: index do column :domain column :user column :created_at column :updated_at end The...

Moving Active Admin index view into its own index.html.arb file

ruby-on-rails,ruby,activeadmin
I'm trying to move out some of the logic for the index/show/edit pages into their own view files. This is because my ActiveAdmin files are just getting to large and overwhelming. At the moment I have active admin page like: # /admin/products.rb ActiveAdmin.register Product do index do selectable_column id_column column...

Rails 4 - eager loading on dependent select causing error (Rails4/Active Admin)

javascript,ruby-on-rails,ruby-on-rails-4,activeadmin,turbolinks
I have an Active panel with a dependent select i.e. the choice on the first dropdown select impacts what appears in the second drop-down. All was working perfectly well a few months ago but i just realized yesterday it is not working any more. I managed to find what cause...