Multistep form with ActiveAdmin?
I've been fretting with this issue myself. I found that you can add your own pages using collection actions in your ActiveAdmin file. Say your model is called MyModel, you would add this to your ActiveAdmin my_model.rb file.
# GET /admin/my_model/page1
collection_action :page1, :method => :get do
render 'admin/page1'
end
# POST /admin/my_model/page1
collection_action :page1, :method => :post do
# Do your form processing
redirect_to test_admin_my_model_path
end
# GET /admin/my_model/page2
collection_action :page2, :method => :get do
render 'admin/page2'
end
You would then need to create a view at /app/views/admin/page1.html.erb and page2.html.erb Multistep form with ActiveAdmin?
I've been fretting with this issue myself. I found that you can add your own pages using collection actions in your ActiveAdmin file. Say your model is called MyModel, you would add this to your ActiveAdmin my_model.rb file.
# GET /admin/my_model/page1
collection_action :page1, :method => :get do
render 'admin/page1'
end
# POST /admin/my_model/page1
collection_action :page1, :method => :post do
# Do your form processing
redirect_to test_admin_my_model_path
end
# GET /admin/my_model/page2
collection_action :page2, :method => :get do
render 'admin/page2'
end
You would then need to create a view at /app/views/admin/page1.html.erb and page2.html.erb How can ActiveAdmin start sorting columns after the first click on columns' header in ascending order?
Unfortunately what you want to do doesn't seem configurable because desc
, the default sort, is hard-coded. However, if you would like a monkey patch, you can put code below in config/initializers/active_admin.rb
which overrides the default behaviour.
module ActiveAdmin
module Views
class TableFor < Arbre::HTML::Table
def order_for_sort_key(sort_key)
current_key, current_order = current_sort
return 'asc' unless current_key == sort_key
current_order == 'desc' ? 'asc' : 'desc'
end
end
end
end
RESTful way to deal with multi-step new action in Rails 3
Have a look at this screencast for a multistep form.
http://railscasts.com/episodes/217-multistep-forms
Ryanb is using a nice way with the validations for each step and keeping everything in the create action so no need to have extra routes.
Creating custom nested forms in RailsAdmin
This isn't a good final answer but I was able to get around the problem with the following JS hack in ui.js
var oldNestedFormEvents = window.nestedFormEvents.insertFields
window.nestedFormEvents.insertFields = function (content, assoc, link) {
if ($(link).closest('.no_tabs').length > 0) {
return $(content).insertBefore(link);
} else {
return oldNestedFormEvents(content, assoc, link);
}
}
On custom partials where I want to use a nested form, I simply add the 'no_tabs' class to their containing div and reuse the original insertFields method from bbenezech-nested_forms. Displaying a comment box on customized ActiveAdmin Show page
I got Answer :-P
ActiveAdmin.register Book do
scope :all, :default => true
scope :publish
show do
attributes_table :name, :description, :owner, :company, :publish, :publisher
active_admin_comments # Add this line for comment block
end
end
Just add "active_admin_comments" at the end of show block. I found it on source code of demo site
How to locate unpermitted params :id in active admin?
It's not the building :id
, it's the address_attributes
that should have the :id
added.
So in building.rb
:
permit_params :name, :construction_year, :floors, :building_type, :energy_label, :owner_id, :manager_id, :project_ids,
address_attributes: [:id, :street, :number, :postal_code, :city]
Related Topics
Docker-Compose Restart Connection Pool Full
How Do Erlang Actors Differ from Oop Objects
How to Open File in Default Application. Ruby
Issue Installing Gems on Windows 7 with Proxy
Rails Routes: Nested, Member, Collection, Namespace, Scope and Customizable
Can't Get Paypal Encrypted Website Payments to Work in Rails
How to Deploy a Test App on Dreamhost Rails 3.0.4
How to Handle Single Table Inheritance in Simpleform So a Single Helper Handles All Models
How to Wait for System Command to End
Changing The Reading Order of Rubygem Sources
What's The Best Way to Test Delayed_Job Chains with Rspec
Is There a Command Line Framework for Ruby
How to Access Parent/Sibling Module Methods
Broken Rails Routes After Implementing Single Table Inheritance