Module: Hammock::ControllerAttributes::ClassMethods
- Defined in:
- lib/hammock/controller_attributes.rb
Instance Method Summary collapse
-
#find_on_create ⇒ Object
When
find_on_create
is specified for a controller, attempts tocreate
new records will first check to see if an identical record already exists. -
#inline_create ⇒ Object
When
inline_create
is specified for a controller, theindex
page will have the ability to directly create new resources, just as thenew
page normally can. - #paginate_by(per_page) ⇒ Object
Instance Method Details
#find_on_create ⇒ Object
When find_on_create
is specified for a controller, attempts to create
new records will first check to see if an identical record already exists. If such a record is found, it is returned and the create is never attempted.
This is useful for the management of administrative records like memberships or friendships, where the user may attempt to create a new record using some unique identifier like an email address. For such a resource, a pre-existing record should not be considered a failure, as would otherwise be triggered by uniqueness checks on the model.
21 22 23 |
# File 'lib/hammock/controller_attributes.rb', line 21 def find_on_create write_inheritable_attribute :find_on_create, true end |
#inline_create ⇒ Object
When inline_create
is specified for a controller, the index
page will have the ability to directly create new resources, just as the new
page normally can.
To use inline_create
, refactor the relevant contents of your new
view into a partial and render it in an appropriate place within the index
view.
A successful create
will redirect to the show
action for the new record, and a failed create
will re-render the index
action with a populated form, in the same way the new
action would normally be rendered in the event of a failed create
.
14 15 16 |
# File 'lib/hammock/controller_attributes.rb', line 14 def inline_create write_inheritable_attribute :inline_create, true end |
#paginate_by(per_page) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/hammock/controller_attributes.rb', line 25 def paginate_by per_page write_inheritable_attribute :pagination_enabled, true mdl..instance_eval do define_method :per_page do per_page end end end |