Activeadmin custom Form
Activeadmin's form definition, with a formtastic base sample
Activeadmin.register Post do
form do |f|
F.inputs ' Details ' do
f.input:title
f.input:p ublished_at, Label: ' Publish Post at '
End
f.actions End End
F.inputs displays a panel that shows all the elements defined within the f.inputs.
F.input an INPUT element, similar to the following: F.action action button.
F.actions a set of operations in which you can define one or more f.action. input type
F.input can define multiple types, such as Check_boxes, select, Radio, and DataList.
Usage:
F.input:authors,: As =>: Check_boxes,: Collection => user.order ("Last_Name ASC"). All f.input:authors,: as => : Check_boxes,: Collection => current_user.company.users.active f.input:authors,: As =>: Check_boxes,: Collection => [@justin, @kate] f.input:authors,: As =>: check_boxes: Collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"] f.input:author,: As =>: SELECT,: Collection => Author.all f.input:author,: As =>: SELECT, : Collection => Author.pluck (: first_name,: ID) f.input:author,: As =>: SELECT,: Collection => author.pl UCK (Arel.sql ("CONCAT (' first_name ', ', ', ' last_name ')"),: ID) f.input:author,: As =>: SELECT,: Collection => Author.your_custom_scope_or_class_method F.input:author,: As =>: SELECT,: Collection => {@justin. Name =&G T @justin. ID, @kate. Name => @kate. ID} f.input:author,: As =>: SELECT,: Collection => ["Justin", "Kate", " Amelia "," Gus "," Meg "]
F.input:author,: As =>: Radio, collection => User.all f.input:author,: As =>: Radio, Colle Ction => [@justin, @kate] f.input:author,: As =>: Radio: Collection => {@justin. Name => @justin. ID , @kate. Name => @kate. ID} f.input:author,: As =>: Radio: Collection => ["Justin", "Kate", "Amelia", "" Gus ", Meg"] f.input:admin,: As =>: Radio,: Collection => ["yes!", "No"] f.input:book_id,: as =>: s Elect,: Collection => hash[book.all.map{|b|
[B.name,b.id]}] F.input:fav_book,:as =>:d atalist: Collection => Book.pluck (: Name)
More Settings
1, set the label: label
F.input:categories,: Label => "category"
2, whether must fill in: Required
F.input:categories,: Required => false
3, note, the default display under the input box: hint
F.input:categories: Hint => "Fill in your ID number here."
4, set the default value
F.input:title,: input_html => {: Value => "This is the title"}
5, hidden fields
F.input:p Ost_id,:as=>:hidden,: input_html => {: Value => "10010"}
6. Complete Type list: AS
: Select–a Select Menu. Default for ActiveRecord associations:belongs_to, Has_many, and Has_and_belongs_to_many.
: Check_boxes–a set of check_box inputs. Alternative to:select for Activerecord-associations:has_many, and Has_and_belongs_to_many.
: Radio–a set of radio inputs. Alternative to:select for activerecord-associations:belongs_to.
: Time_zone–a Select Input. Default for column types:: string with name matching "Time_zone".
:p assword–a Password input. Default for column types:: string with name matching "password".
: Text–a textarea. Default for column types:: Text.
:d ate_select–a Date Select. Default for column types::d ate.
:d atetime_select–a Date and time select. Default for column types::d atetime and:timestamp.
: Time_select–a time Select. Default for column types:: Time.
: Boolean–a checkbox. Default for column types:: Boolean.
: String–a text field. Default for column types:: String.
: Number–a text field (just like string). Default for column types:: Integer,: float, and:d ecimal.
: File–a file field. Default for file-attachment attributes Matching:paperclip or Attachment_fu.
: Country–a Select menu of country names. Default for column types:: string with Name ' country ' –requires a Country_select plugin to be installed.
: Email–a text field (just like string). Default for columns with name matching "email". New in HTML5. Works on some mobile browsers already.
: Url–a text field (just like string). Default to columns with name matching "url". New in HTML5. Works on some mobile browsers already.
:p hone–a Text field (just like string). Default for columns with name matching "Phone" or "fax". New in HTML5.
: Search–a text field (just like string). Default for columns with name matching "search". New in HTML5. Works on Safari.
: Hidden–a hidden field. Creates a hidden field (added for compatibility).
: Range–a slider field.
:d atalist–a text field with a accompanying DataList tag which provides options for autocompletion
7. Data set: Collection
With: As =>: Check_boxes,: As =>: SELECT,: As =>: Radio,: As =>:d atalist use. Resources
Https://github.com/justinfrench/formtastic
Http://activeadmin.info/docs/5-forms.html