How can I use yard doc in ActiveAdmin? - ruby-on-rails

When I add a new index page in activeadmin, I write some code like this:
# A default activeadmin page for yard overview
ActiveAdmin.register AdminUser do
permit_params :email, :password, :password_confirmation
index do
column :email
column :current_sign_in_at
column :last_sign_in_at
column :sign_in_count
default_actions
end
filter :email
form do |f|
f.inputs "Admin Details" do
f.input :email
f.input :password
f.input :password_confirmation
end
f.actions
end
end
In fact the activeadmin had create some view and controller, and I want to display some document info in yard server, but the yarddoc ignore this file.
What should I do ?

You can not write documentation because Active Admin is Domain-specific language. Write good comments I do not see any other way.

Related

Rails ActiveAdmin - How to remove Add New button which is added by default?

In rails 6, I am using activeadmin gem for admin interface.
My code is like,
ActiveAdmin.register Account, as: "Individual Accounts" do
menu parent: "Accounts", label: "Individual Accounts"
permit_params :first_name, :last_name, :email, :password, :role_id
filter :first_name
filter :email
index do
selectable_column
column :first_name
column :last_name
column "Role" do |acc|
acc.role
end
column :email
actions
end
form do |f|
f.inputs do
f.input :first_name
f.input :last_name
f.input :email
f.input :password
end
f.actions
end
show do
attributes_table do
row :role
row :first_name
row :last_name
row :email
end
end
controller do
after_create :set_account_type
def set_account_type resource
resource.type = "EmailAccount"
role = RolesPermissions::Role.find_by(name:"Individual")
resource.role_id = role.id
resource.save
end
def create
super do |success,failure|
success.html { redirect_to admin_individual_accounts_path }
end
end
end
controller do
def scoped_collection
Account.joins(:role).where(roles: {name: "Individual"})
end
end
end
I want to remove New Individual Accounts button(option) from the page.
If I try to override an action_item like as mentioned below then one more button will get add
action_item only: :new do
link_to 'Add New', new_admin_individual_account_path
end
Please help me to remove new option.

Active admin Place a form above the table

I have an application using active admin. All I tried to achieve is , to show a form above the active admin table. When the form is submitted , a request is placed which will be displayed in the table below the form. What I tried is,
Tried to render the form in a panel within index
Tried to have 2 index, one with the table and the other with rendering the form
The problem I faced in the above two solutions is , when there are no records in the table , the form is also not shown . When the table has records, the form is displayed
Is there a way so that the form is shown even if there are no records in index table. or, other ways of showing the form above the table. I also tried to write custom index, but could not locate the exact documentation for that
First off, to render a form you normally do:
form html: {:multipart => true} do |f|
f.inputs do
f.input :name
f.input :content
f.input :description
f.input :price
f.input :plan
f.input :image, hint: f.project.image? ? image_tag(project.image.url, height: '100') : content_tag(:span, "Upload JPG/PNG/GIF image")
end
f.actions
end
inside the model. In my case it was projects.rb for project.rb
If you want to render a form via partial, simply do:
# renders app/views/admin/posts/_some_partial.html.erb
render 'some_partial', { post: post }
this will render any form into your admin panel.
If you want to insert an index:
ActiveAdmin.register Task do
permit_params :title, :note, :video, :header, :tag, :project_id
sortable tree: false, sorting_attribute: :tag
index :as => :sortable do
label :title
actions
end
index do
selectable_column
column :header
column :title
column :tag
column :project
actions
end
end

ActiveAdmin bcrypt users password on update or insert rails

I am using ActiveAdmin as a admin panel, so I can create users through ActiveAdmin.
The Issue I'm having is when updating or inserting a users password, I need the value I entered in the ActiveAdmin form to hash the password with bcrypt and then work with rails has_secure_password authentication
Is there anyway I can get ActiveAdmin to include something like this?
BCrypt::Password.create(params[:password])
before saving to the database?
this is my users.rb
ActiveAdmin.register User do
permit_params :email, :password_digest, :session_token, :session_key,
:rank, :profileColour
index do
selectable_column
id_column
column :email
column :password_digest
column :session_token
column :session_key
column :rank
column :profileColour
actions
end
filter :email
filter :session_token
filter :session_key
filter :rank
filter :profileColour
form do |f|
f.inputs "Admin Details" do
f.input :email
f.input :password_digest
f.input :rank
end
f.actions
end
end
Any advice would be greatly appreciated
Thanks!
Try to use :password instead of :password_digest
form do |f|
f.inputs "Admin Details" do
f.input :email
f.input :password
# f.input :password_confirmation
f.input :rank
end
f.actions
end
Don't forget to permit params
ActiveAdmin.register User do
permit_params :email, :password, :rank
end

Ruby On Rails Active Admin has_many changing text to use a different column

This is similar to my previous question Ruby On Rails Active Admin has_many changing dropdown to use a different column
I figured out how to reassign a f.inputs but how would i go about reassigning the display of the data when viewing an item...
e.g:
Public Git Repo: https://github.com/gorelative/TestApp
Snippet of code i have in my fillups.rb
ActiveAdmin.register Fillup do
form do |f|
f.inputs do
f.input :car, :collection => Car.all.map{ |car| [car.description, car.id] }
f.input :comment
f.input :cost
f.input :mileage
f.input :gallons
f.buttons
end
end
end
Modify the show action
ActiveAdmin.register Fillup do
# ... other stuff
show do
attributes_table do
# add your other rows
row :id
row :car do |fillup|
link_to fillup.car.description, admin_car_path(fillup.car)
end
end
end
end

Adding New Admins to Active Admin

I am using devise for my users. I recently installed the rails Active Admin gem, everything is working beautifully.
However I can't figure out how to add a new admin users. I can see that active admin created an admin_user table in the db with a user admin#example.com, which I use to log in to the interface.
I tried adding admin_user as a resource so that I can just click the Add Admin User button within the active admin interface to add a new user, however that does not seem to work.
What brian said works perfectly
http://net.tutsplus.com/tutorials/ruby/create-beautiful-administration-interfaces-with-active-admin/
AdminUser.create!(:email => 'admin#example.com', :password => 'password', :password_confirmation => 'password')
What Brian said works, but if you want to set the password in the interface rather than have it send a reset email try this:
Leave the admin_user model at its original generated default, then in app/admin/admin_users.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
form do |f|
f.inputs "Admin Details" do
f.input :email
f.input :password
f.input :password_confirmation
end
f.buttons
end
end
login: admin#example.com password: password => login
go to http://localhost:3000/admin/admin_users
If you want create users (devise users, table "users") in admin panel:
$ rails generate active_admin:resource user
app/admin/user.rb:
ActiveAdmin.register User do
permit_params :email, :name, :password, :password_confirmation
index do
column :name
column :email
actions
end
form do |f|
f.inputs 'User' do
f.input :name
f.input :email
f.input :password
f.input :password_confirmation
end
f.actions
end
end
this is the new syntax
AdminUser.create!(email: "youremail#domain.com", password: "password123", password_confirmation: "password123")

Resources