smallseo.info

activeadmin

The administration framework for Ruby on Rails applications.

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)

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)

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)

How to get current user using devise in rails without using authenticate! on the controller

I'm using devise with rails 3 and i'm trying to create a page which can be viewed by everyone (even those not signed up) but has additional functionality for people who are registered.

The problem is that when I call current_user there is no user because I haven't used the authenticate! filter on my controller, because I want unregistered users to be able to view it.

How do I sign in a user if they are in the session otherwise leaving it without a user?


Source: (StackOverflow)

How to Properly Configure Rails 4.1 Enums in ActiveAdmin

I've got a Rails 4.1 app in which I use an enum to represent the privacy level of an object.

In my schema:

t.integer "privacy_level", default: 0

In my model:

enum privacy_level: { privacy_private: 0, privacy_trusted: 1, privacy_public: 2 }

In my ActiveAdmin register file:

index do
  column :privacy_level
  default_actions
end

form do |f|
  f.inputs "Edit My Model" do
    f.input :privacy_level
  end
  f.actions
end

On the ActiveAdmin index page, it works great. The privacy level of each object shows up as "privacy_private", "privacy_trusted", and "privacy_public".

However, when I try to edit an object, the input type is a number box with up and down arrows which allow me to put any integer in, regardless of whether or not the integer is a valid privacy level (even negative values).

What I would like to see is a dropdown (select) input with the three enumerated string values I defined in my model.


Source: (StackOverflow)

How can I customize the active admin layout?

I need to customize the active admin layout, but how can I do it?


Source: (StackOverflow)

Activeadmin overides my css

First I have created an active_admin css file "active_admin.css.scss" on app/assets/stylesheets/active_admin.css.scss

/* active_admin.css.scss */
@import "active_admin/mixins";
@import "active_admin/base";

/* application.css.scss*/
@import "active_admin.css.scss"

So I have a lot of css of mine been overided, I followed instructions of this post http://robertomurray.co.uk/blog/2011/rails-fix-activeadmin-css-over-riding-problem but still doesn't work. I change file's location from app/assets/stylesheets/active_admin.css.scss to vendor/assets/stylesheets/active_admin.css.scss but still having the problem.

So I guess my question is how can I load activeadmin css files only when they actually nedded ?


Source: (StackOverflow)

Rails 3. How to add a helper that ActiveAdmin will use?

I'm creating a helper to be used by Formtastic but I get the undefined local variable or method error. I don't know where to put it so it can work.

I already tried in the application_helper.rb and in app/helpers/active_admin/view_helpers.rb


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)