-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for selectable strings on edit pages
- Loading branch information
1 parent
d0bc1c7
commit 2c4ed97
Showing
10 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<%# | ||
# Select Index Partial | ||
This partial renders a selectable text attribute, | ||
to be displayed on a resource's edit form page. | ||
## Local variables: | ||
- `f`: | ||
A Rails form generator, used to help create the appropriate input fields. | ||
- `field`: | ||
An instance of [Administrate::Field::Select][1]. | ||
A wrapper around the attribute pulled from the database. | ||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Select | ||
%> | ||
|
||
<div class="field-unit__label"> | ||
<%= f.label field.attribute %> | ||
</div> | ||
<div class="field-unit__field"> | ||
<%= f.select( | ||
field.attribute, | ||
options_from_collection_for_select(field.selectable_options, :to_s, :to_s) | ||
) %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<%# | ||
# Select Index Partial | ||
This partial renders a selectable text attribute, | ||
to be displayed on a resource's index page. | ||
## Local variables: | ||
- `field`: | ||
An instance of [Administrate::Field::Select][1]. | ||
A wrapper around the attribute pulled from the database. | ||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Select | ||
%> | ||
|
||
<%= field.data.presence %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<%# | ||
# Select Show Partial | ||
This partial renders a selectable text attribute, | ||
to be displayed on a resource's show page. | ||
## Local variables: | ||
- `field`: | ||
An instance of [Administrate::Field::Select][1]. | ||
A wrapper around the attribute pulled from the database. | ||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Select | ||
%> | ||
|
||
<%= field.data.presence %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require_relative "base" | ||
|
||
module Administrate | ||
module Field | ||
class Select < Field::Base | ||
def self.searchable? | ||
true | ||
end | ||
|
||
def selectable_options | ||
collection | ||
end | ||
|
||
private | ||
|
||
def collection | ||
@collection ||= options.fetch(:collection, []) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
spec/example_app/db/migrate/20160119024340_add_kind_to_customer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddKindToCustomer < ActiveRecord::Migration | ||
def change | ||
add_column :customers, :kind, :string, null: false, default: "standard" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters