Adding description paragraph to ActiveAdmin /new Page - ruby-on-rails

I have a page set up on ActiveAdmin and when the user clicks the "Create One" button, I want to add a short textbox on the /new page (either at the top or part of the actual form, whatever's easier) explaining what needs to be put into the form.
How can I do this?

Active Admin gives complete control over the output of the form by creating a thin DSL on top of the fabulous DSL created by Formtastic (http://github.com/justinfrench/formtastic).
And you can add :hint for each form input like this:
form do |f|
f.inputs 'Details' do
f.input :title, :required => true, :hint => "This field should be filled in"
end
f.inputs 'Advanced' do
f.input :keywords, :hint => "Example: ruby, rails, active-admin"
...
end
end
Take a look Formtastic documentation, there is lot of capabilities...

You can simply add new description column in your model or you can use active admin comments here is comments description for active admin.
Hope it would help you.

Related

text_field_tag with ActiveAdmin

I've a hard time with ActiveAdmin and their DSL. I'm using it to build my admin and at some point in a form I need to have a text_field_tag; I mean some fields which aren't related to the model I'm manipulating in the form which will be sent through with the model related data.
A custom text field basically. Nothing too crazy.
So I've built this
panel 'Send payment authorization' do
active_admin_form_for EventPaymentAuthorization.new, url: { action: :send_event_payment_authorization } do |f|
f.inputs do
f.input :body, as: :text
f.text_field_tag :line_items_label
f.text_field_tag :line_items_amount
f.input :fees_in_cents, as: :select, collection: [:free, :automatic], prompt: true, selected: :automatic
end
f.actions do
f.action :submit, label: 'Create payment authorization'
end
end
end
The f.text_field_tag get simply ignored by ActiveAdmin. Why is that? It doesn't raise any error, but it doesn't show either.
The reason I need custom unrelated inputs is because line_items in my example is a JSONB with values such as [{amount: 0.0, label: 'Hello'}] and I don't believe it can be processed through Formtastic or ActiveAdmin natively. It's also always good to be able to create custom inputs when sending data.
Working with JSON in ActiveAdmin is a bit tricky, it largely depends on your needs. The quickest way to get going is to use the activeadmin_json_editor gem. I also wrote a blog entry on working with JSON in ActiveAdmin with more detail and another approach, which may better suit your needs, as it appears you are not just working with arbitrary data into your JSON field.

ActiveAdmin: display parameter of object selected in form

I am not very familiar with ActiveAdmin or rails in general, so sorry if I use some incorrect phrasing.
I have a model for an Athlete, which has an attribute "notes". This is described in the permit_params of the athlete.rb.
On an additional page, I have the following:
f.input :athlete, :collection => Athlete.all.sort_by(&:last_name), :required => true
I would like to find a way to, if the :notes is not empty, display it.
If I could display it as a "row" on the form, that would be great.
Thanks!

Pass a parameter to the new action in Active Admin

I have two related models, Bunny has_many BunnyData (which belongs_to Bunny). From the show page of a particular Bunny (in Active Admin), I want to create a link to make a related BunnyData. I've tried a few different ways, with no success, and am currently trying this:
sidebar :data, :only => :show do
link_to 'New Data', new_admin_bunny_datum(:bunny_id => bunny.id)
end
The link being generated ends up as something like:
.../admin/bunny_data/new?bunny_id=5
But when you go to that page, the dropdown for Bunny is set to the blank default as opposed to showing the name of Bunny with ID 5.
Thanks in advance.
Rails namespaces form fields to the data model, in this case BunnyData. For the form to be pre-filled, any fields provided must also include the namespace. As an example:
ActiveAdmin.register Post do
form do |f|
f.inputs "Post Details" do
f.input :user
f.input :title
f.input :content
end
f.actions
end
end
The fields can be pre-filled by passing a hash to the path helper.
link_to 'New Post', new_admin_post_path(:post => { :user_id => user.id })
Which would generate the following path and set the form field.
/admin/posts/new?post[user_id]=5
In the case of BunnyData, it might be slightly different due to the singular and plural forms of datum. But that can be verified by inspecting the generated HTML to find the name attribute of the inputs.

Rails 4 + ActiveAdmin: Attribute limited to a few values -- customizing ActiveAdmin form based on this?

So I have a CareerEntry model that has a fullintern attribute, which is a string that is supposed to specify whether the entry represents an internship or a full-time position. I limit the values that can appear in this attribute as follows:
validates_inclusion_of :fullintern, :in => ["Internship", "Full-time"]
However, in ActiveAdmin, the part in the edit form that deals with the fullintern attribute still has a text field. How do I make it a dropdown box where the admin can select either "Internship" or "Full-time"?
Thanks.
You can use Formtastic's input helpers to use a select input:
form do |f|
f.inputs "Details" do
f.input :fullintern, as: :select, collection: ["Internship", "Full-time"]
end
f.actions
end
See Formtastic's usage section for the full set of native capabilities.

Manipulating tags with acts_as_taggable_on and ActiveAdmin

I have a Post model which I'm accessing through ActiveAdmin. It's also taggable using the acts_as_taggable_on gem. So the admin can add, edit or delete tags from a specific Post.
The normal way to add the tagging functionality for the resource in your admin panel is by doing this in admin/posts.rb:
ActiveAdmin.register Post do
form do |f|
f.inputs "Details", :multipart => true do
f.input :tag_list
# and the other irrelevant fields goes here
end
f.buttons
end
end
However, I want to have the tags selected from a multiple select form field and not being entered manually in a text field (like it is with the code above). So I've tried doing this:
f.input :tag_list, :as => :select,
:multiple => :true,
:collection => ActsAsTaggableOn::Tag.all
but it doesn't work as expected. This actually creates new tags with some integer values for names and assigns them to that Post. Someone told me that extra code is needed for this to work.
Any clues on how this is done? Here's my model just in case: http://pastie.org/3911123
Thanks in advance.
Instead of
:collection => ActsAsTaggableOn::Tag.all
try
:collection => ActsAsTaggableOn::Tag.pluck(:name)
Setting the collection to Tag.all is going to tag your posts with the tag's ID, since that's how tags are identified by default (that's where the integer values for names are coming from). map(&:name) tells the form builder to use the tag's name instead.

Resources