smallseo.info

activeadmin

The administration framework for Ruby on Rails applications.

Active admin install with Rails 4

I got this error when installing active admin on Rails 4

Bundler could not find compatible versions for gem "actionpack":
In Gemfile:
  meta_search (>= 1.1.0.pre) ruby depends on
    actionpack (~> 3.1.0.alpha) ruby

  rails (= 4.0.0.rc1) ruby depends on
    actionpack (4.0.0.rc1)

I follow this instruction: http://www.activeadmin.info/docs/documentation.html

Anyone help please.


Source: (StackOverflow)

ActiveAdmin with has_many problem; undefined method 'new_record?'

I'm trying to customise a ActiveAdmin form for a Recipe model that has a has_many relationship with Step.

class Recipe < ActiveRecord::Base
  has_many :steps
end

class Step < ActiveRecord::Base
  acts_as_list :scope => :recipe

  belongs_to :recipe
end

I have the following in my ActiveAdmin file with relation to this:

form do |f|
  f.has_many :steps do |ing_f|
    ing_f.inputs
  end
end

The following error is thrown when I try to load the form:

undefined method `new_record?' for nil:NilClass

I've isolated it so far to the has_many method but I'm lost past this. Any advice and help would be appreciated!


Source: (StackOverflow)

How to use ActiveAdmin on models using has_many through association?

I am using ActiveAdmin gem in my project.

I have 2 models using has_many through association. The database schema looks exactly the same as the example in RailsGuide. http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association has_many through association

How can I use ActiveAdmin to ...

  1. show appointment date of each patient in physicians page?
  2. edit appointment date of each patient in physicians page?

Thanks all. :)


Source: (StackOverflow)

Rails Activeadmin - custom association select box

In my Rails application, I have the following model:

class Idea < ActiveRecord::Base
  belongs_to :user
end

class User < ActiveRecord::Base
  has_many :ideas
end

I am creating ActiveAdmin CRUD for my Idea model with the custom form that looks something like that looks something like that:

form do |f|
  f.inputs do
    f.input :member
    f.input :description
  end
end

The requirement is to have the custom text for a content of the member association, i.e "#{last_name}, #{first_name}". Is it possible to customize my member select box to achieve it?

Any help will be appreciated.


Source: (StackOverflow)

How to add custom filter to Active Admin?

Active Admin allows me to define filters that are displayed on the index page like so:

ActiveAdmin.register Promo do

  filter :name
  filter :address
  filter :city
  filter :state
  filter :zip

end

I would like to combine all the fields above into one, so that I can search for Promos that contain the search string in name or full address. My model already has a named scope that I can use:

class Promo < ActiveRecord::Base
  scope :by_name_or_full_address, lambda { |q| where('name LIKE :q OR address LIKE :q OR city LIKE :q OR state LIKE :q OR zip LIKE :q', :q => "%#{q}%") }
end

Source: (StackOverflow)

ActiveAdmin Error: no superclass method `buttons'

I'm starting with Rails (and I'm also new with Ruby -coming from Python-) and I'm currentrly trying to setup ActiveAdmin for Rails 3.2.3 (Ruby 1.9.3). I'm following this guide but I was not able to run it properly. When I run the rails s command visiting localhost:3000/admin I get

NoMethodError in Active_admin/devise/sessions#new

Showing /home/lex/.rvm/gems/ruby-1.9.3-p125/gems/activeadmin-0.4.3/app/views/active_admin/devise/sessions/new.html.erb where line #11 raised:

super: no superclass method `buttons' for #<ActiveAdmin::FormBuilder:0xb429ae0>

I could not find anything useful on Google, what's wrong here?

If you need more info about this exception please tell me.

Extracted source (around line #11):

8:       f.input :password
9:       f.input :remember_me, :as => :boolean, :if =>  false  #devise_mapping.rememberable? }
10:     end
11:     f.buttons do
12:       f.commit_button "Login"
13:     end
14:   end

Source: (StackOverflow)

Paperclip + Active_admin + Rails 3.0.10 multiple images

I have a crud with paperclip and multiple images' i implement active_admin and the product update fine, but, i can't not upload or edit the multiple images, the form i have is this:

form :html => { :multipart => true } do |f|
  f.inputs "Details" do
    f.input :name
    f.input :created_at, :label => "Publish Product at"
    f.input :category
  end

  f.inputs "Images" do
    f.has_many :assets do |p|
      p.input :asset, :as => :file, :input_html => { :multiple => true }, :label => "Image", :hint => p.object.asset.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.asset.url(:thumb))
      p.input :_destroy, :as=>:boolean, :required => false, :label=>'Remove'
    end
  end

  f.inputs "Content" do
    f.input :description
  end
  f.buttons
end

and the...

f.inputs "Images" do
    f.has_many :assets do |p|
      p.input :asset, :as => :file, :input_html => { :multiple => true }, :label => "Image", :hint => p.object.asset.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.asset.url(:thumb))
      p.input :_destroy, :as=>:boolean, :required => false, :label=>'Remove'
    end
  end

I want to upload images, but when i create a new asset this have a missing image default and not attach the correct image, i think because the path from the images is not correct to upload. My asset model is:

 class Asset < ActiveRecord::Base
   belongs_to :product
   has_attached_file :asset, :styles => { :large => "340x330", :medium => "140x80>", :thumb => "70x70>" },
     :url => "/products/:id/:style/:basename.:extension",  
     :path => ":rails_root/public/products/:id/:style/:basename.:extension"
 end

how i can modify my assets form to work like i want? Thank you!


Source: (StackOverflow)

Why are my Rails assets getting precompiled twice?

I've noticed my assets seem to get compiled twice, which considerably slows down my deployment, as this step is the most time consuming part:

~/projects/rewportal(mapwidget ✔) rake assets:precompile
/home/ruy/.rvm/rubies/ruby-1.9.3-p194/bin/ruby /home/ruy/.rvm/gems/ruby-1.9.3-p194@rewportal/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
AssetSync: using /home/ruy/projects/rewportal/config/initializers/asset_sync.rb
AssetSync: using /home/ruy/projects/rewportal/config/initializers/asset_sync.rb
AssetSync: Syncing.
Using: Directory Search of /home/ruy/projects/rewportal/public/assets
Uploading: assets/application-5170f52c1dd49cb382d5135bee01d75e.js
[...]
Fetching files to flag for delete
Flagging 8 file(s) for deletion
Deleting: assets/active_admin-4ce46d089d4b0080e87c9abcb6fa6c97.css
[...]
AssetSync: Done.

It this normal?

When I precompile to other environments (non-production), I can see the detailed compilation of each asset twice:

~/projects/rewportal(mapwidget ✔) rake RAILS_ENV=qa assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/home/ruy/.rvm/rubies/ruby-1.9.3-p194/bin/ruby /home/ruy/.rvm/gems/ruby-1.9.3-p194@rewportal/bin/rake assets:precompile:all RAILS_ENV=qa RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
AssetSync: using /home/ruy/projects/rewportal/config/initializers/asset_sync.rb
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
Compiled gmaps4rails/gmaps4rails.base.js  (141ms)  (pid 8480)
Compiled gmaps4rails/gmaps4rails.googlemaps.js  (148ms)  (pid 8480)
[...]
Compiled active_admin.css  (1299ms)  (pid 8480)
Compiled active_admin/print.css  (113ms)  (pid 8480)
** Invoke assets:precompile:nondigest (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
AssetSync: using /home/ruy/projects/rewportal/config/initializers/asset_sync.rb
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:nondigest
Compiled gmaps4rails/gmaps4rails.base.js  (133ms)  (pid 8480)
Compiled gmaps4rails/gmaps4rails.googlemaps.js  (133ms)  (pid 8480)
[...]
Compiled active_admin.css  (1290ms)  (pid 8480)
Compiled active_admin/print.css  (116ms)  (pid 8480)
AssetSync: Syncing.
Using: Directory Search of /home/ruy/projects/rewportal/public/assets
Uploading: assets/active_admin-d05b61ab8366b74eabc9074d3e60fe82.css.gz
[...]
Fetching files to flag for delete
Flagging 6 file(s) for deletion
Deleting: assets/active_admin-ec90e7d9a9f45f14d1387f58fa1452b4.css
[...]
AssetSync: Done.

My application.rb has the following:

config.assets.precompile += %w( active_admin/print.css active_admin.css active_admin.js admin.js admin.css html5shiv.js )

Ideas?


Source: (StackOverflow)

ActiveRecord::ReadOnlyRecord when using ActiveAdmin and Friendly_id

I started using ActiveAdmin recently in a project and almost everything works great but I'm having a problem when using it in combination with the friendly_id gem. I'm getting ActiveRecord::ReadOnlyRecord thrown for my forms [i believe] because of the friendly_id attribute whose ID is readonly:

{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"Rc5PmUYZt3BiLvfPQr8iCPPXlbfgjoe/n+NhCwXazNs=",
"space"=>{"name"=>"The Kosmonaut",
"address"=>"8 Sichovykh Striltsiv 24",
"email"=>"info@somedomain.com"},
"commit"=>"Update Space",
"id"=>"the-kosmonaut"}  <--- culprit

I'm guessing the last line is the culprit as it's a readonly attribute, it's not in my form but rather in the PATH

http://localhost:5000/manage/spaces/the-kosmonaut/edit

How can I fix this from trying to update the ID?

Form from in ActiveAdmin looks like this:

  form do |f|
    f.inputs "Details" do
      f.input :name
      f.input :address
      f.input :email
      f.input :phone
      f.input :website
    end
    f.inputs "Content" do
      f.input :description
      f.input :blurb
    end
    f.buttons
  end

UPDATE: This doesn't work either so it's not the friendly_id?

I tried using @watson's suggestion which should have worked but still got the same error ;-(

{"utf8"=>"✓",
 "_method"=>"put",
 "authenticity_token"=>"Rc5PmUYZt3BiLvfPQr8iCPPXlbfgjoe/n+NhCwXazNs=",
 "space"=>{"name"=>"The Kosmonaut 23"},
 "commit"=>"Update Space",
 "id"=>"6933"}

http://localhost:5000/manage/spaces/6933/edit

When I check the record in the console with record.readonly? it returns false

UPDATE UPDATE: removing the scope_to fixes the problem.

scope_to :current_user, :unless => proc{ current_user.admin? }

Only problem is I need the scope_to to prevent users from seeing records they do not own. My guess is (as I'm assuming scope_to normally works with has_many) that my HABTM association causes some weirdness? Ie Users <-- HABTM --> Spaces?


Source: (StackOverflow)

Setting root page to activeAdmin default login page

Im having dificulty in setting the root page in may Rails app to the default login page of the Active Admin gems, at localhost:3000/admin/login. Here's my routes.rb:

TestActiveadmin::Application.routes.draw do
  ActiveAdmin.routes(self)

  devise_for :admin_users, ActiveAdmin::Devise.config

  match 'login' => 'sessions#new', :as => :login
  match 'signup' => 'users#new', :as => :signup
  match 'logout' => 'sessions#destroy', :as => :logout
  resources :sessions
  resources :users

end

What should I do?


Source: (StackOverflow)

Image file input with Formtastic and ActiveAdmin

I started to use formstatic but I need to make a file field with image preview. I mean, when i edit an object, i want to see the image already linked.

How can I do that?

Thank you !


Source: (StackOverflow)

rails ActiveAdmin nested form has_one accepts_attributes_for formtastic issue

I am using ActiveAdmin and Rails 3.1 -- having problem understanding whether the following is a bug, or if there is some way to do it correctly that I am not understanding. I am trying to use a nested model with a has one relationship, so that I can create a page and fill out it's meta data in 1 step. -- (page has_one meta_data, accepts_nested_attributes_for meta_data)

Example 1) in this example, when I click new page, meta data section is there but there are no input fields -- also, if I edit the record, it shows up correctly, however the fieldset is duplicated in the second section... and if I remove the f.inputs wrapping semantic_field_for (which would make sense), then it breaks completely and shows nothing in the meta data area...

form do |f|
  f.inputs "Page Information" do
    f.input :name
    f.input :uri
    f.input :view
    f.input :body, :as => :text
    f.input :active
  end

  f.inputs "Meta Data" do
    f.semantic_fields_for :meta_data do |meta_form|
      meta_form.inputs :title, :description, :keywords, :name => "Meta Information"
    end
  end  
end

I understand the meta data probably isn't being instantiated, but I am not sure how I am supposed to do that in the form block? (or if I can even do it) -- The only way I am able to get this to work is by doing using a custom form, and building the meta data in the view, which looks like this

2) How I am working around it, but seems hacky

<%= semantic_form_for [:admin, @page] do |f| %>
  <% @page.build_meta_data %>
  <%= f.inputs :name => "Page Information" do  %>
    <%= f.input :name %>
    <%= f.input :uri %>
    <%= f.input :view %>
    <%= f.input :body, :as => :text %>
    <%= f.input :active %>
  <% end %>
  <%= f.semantic_fields_for :meta_data do |meta_form| %>
    <%= meta_form.inputs :title, :description, :keywords, :name => "Meta Information" %>
  <% end %>

  <%= f.buttons %>
<% end %>

Thanks in advance for any help or clarification.

(note to moderators I started another thread on this but was not as clear and didn't have the workaround solution I do now yet, so if one of the questions should be deleted please delete the other)


Source: (StackOverflow)

Remove 'Show' link from ActiveAdmin default_actions

I've made a title of my resources as a link to a Show action. Now I want to remove that link form default_actions.

actions :all, :except => [:show]

Won't do because I need show action to be available.

I'le also tried

column do |show|
  links = ''.html_safe
  links += link_to "Edit", edit_admin_show_path(show)
  links += ' '
  links += link_to "Del", admin_show_path(show), :confirm => 'Are you sure?', :method => :delete
  links
end

But delete link isn't working but rather takes me to the Show page.

I'll be thankful for any help


Source: (StackOverflow)

Nested form in active_admin with select or create option

We are using active_admin for our administration backend.

We have a model "App" that :belongs_to model "Publisher":

class App < ActiveRecord::Base
  belongs_to :publisher
end

class Publisher < ActiveRecord::Base
  has_many :apps
end

When creating a new entry for the "App" model I want to have the option to either select an existing publisher or (if the publisher is not yet created) to create a new publisher in the same (nested) form (or at least without leaving the page).

Is there a way to do this in active_admin?

Here's what we have so far (in admin/app.rb):

form :html => { :enctype => "multipart/form-data" } do |f|
  f.inputs do
    f.input :title
    ...
  end

  f.inputs do
    f.semantic_fields_for :publisher do |p| # this is for has_many assocs, right?
      p.input :name
    end
  end

  f.buttons
end

After hours of searching, I'd appreciate any hint... Thanks!


Source: (StackOverflow)

ActiveAdmin: how to leave user password unchanged?

I uses ActiveAdmin as my administration backend in my rails app. Basically, I have a admin_user and a user model.

When I create a new user from an admin account, I specify an email and a password, that is ok.

Let's say I then want to modify the user's email but not the password... it seems this cannot be done as the password field cannot be blank when updating a user.

Is there a configuration somewhere that would consider that the password is unchanged is the fields (password and password_confirmation) are left blank while updating a user ?


Source: (StackOverflow)