Skip to content

Releases: hot-glue-for-rails/hot-glue

v0.6.4 - More pickup partials + Rails 7.1 fix

09 Aug 02:22
b87c5c5
Compare
Choose a tag to compare

(rerelease of v6.0.3.3)

• Adds pickup partials for

_index_before_list
_list_after_each_row
_list_after_each_row_heading

Remember, to use pickup partials these partials must exist in the build folder at the time you are building scaffolding.

• Fixes issue with Rails 7.1 when using --no-edit or --no-delete flags
(Rails 7.1 enforces the presence of action names flagged with only on the before hook, which caused The show action could not be found for the :load_charge callback...)

v0.6.3.3 - More pickup partials + Rails 7.1 fix

29 Jul 17:34
44a6db7
Compare
Choose a tag to compare

• Adds pickup partials for

_index_before_list
_list_after_each_row
_list_after_each_row_heading

Remember, to use pickup partials these partials must exist in the build folder at the time you are building scaffolding.

• Fixes issue with Rails 7.1 when using --no-edit or --no-delete flags
(Rails 7.1 enforces the presence of action names flagged with only on the before hook, which caused The show action could not be found for the :load_charge callback...)

v0.6.3.2 - Minor cleanup

29 Feb 20:45
fa70bcd
Compare
Choose a tag to compare

I released this to Rubygems on 1/18 but neglected to do these release notes in GH until today.

  • corrects variables to be top-level in for nested merge in edit.erb; also adds new flag --display-edit-after-create used to direct to the edit page after the create action (#157)
  • code spacing tweaks
  • picks up all columns if no search fields specified
  • fixes top_level setting on edit.erb

v0.6.3.1 - Set searching - boolean modified datetime fields search

17 Jan 01:41
ad9e45c
Compare
Choose a tag to compare

Adds support for boolean modified datetime search; now, when using a modify= to turn a datetime into a boolean, the search box behaves appropriately and shows a 3-way radio picker: all, falsy, truthy.
(Only implemented for datetime)

Example
Assuming you have an Account model with these fields, this interface creates a search only on the confirmed_at datetime.

bin/rails generate hot_glue:scaffold Account --gd --namespace='admin' --include='company_name,email:first_name,last_name:confirmed_at' --show-only='confirmed_at' --modify='confirmed_at{confirmed|unconfirmed}' --search=set --search-fields=confirmed_at

boolean modified datetime 2

v0.6.3 - Set Searching

16 Jan 00:05
b994308
Compare
Choose a tag to compare

Set Searching

--search (options: set, false default: false)

(Future options include simple, predicate)

A set search is a search form that allows you to search across multiple fields at once. It is a set of search fields, each of which is a search field for a single field.

Set Search

If you specify --search to set, you will get a whole bar across the top of the list with search fields for each field.
Within the set, the search query is combinative ("and"), so records matching all criteria are shown as the result set.
For date pickers, time pickers, and the clear form interaction, you need the additional Stimulus JS.
Install this with :

bin/rails generate hot_glue:set_search_interface_install

Additional search option for Set Search

--search-fields=aaa,bbb,ccc,ddd,eee

to specify which fields you want to be searchable.

--search-query-fields=aaa,ddd

to specify a list of strings only which will be taken out of the search set and presented in a singular query box (allowing search across multiple string fields)

--search-position=vertical

to specify vertical or horizontal (default: horizontal)

--search-clear-button (no option)

to specify whether to show a clear button to clear the whole search form at once (default: false)

v0.6.2 - Cook hooks & other fixes

02 Dec 17:11
7e01fee
Compare
Choose a tag to compare

Fixes to typeahead when using Pundit.

New Code Hooks: Add Custom Code Before/After the Update or Create Actions

--code-before-create
--code-after-create
--code-before-update
--code-after-update

Insert some code into the create action or update actions.

The before code is called after authorization but before saving (which creates the record, or fails validation).

The after create code is called after the record is saved (and thus has an id in the case of the create action).

Both should be wrapped in quotation marks when specified in the command line, and use semicolons to separate multiple lines of code.
(Notice the funky indentation of the lines in the generated code. Adjust you input to get the indentation correct.)

• New Automatic Pickup Partial Includes for _edit and _new Screens

Pickup Partial Includes for _edit and _new Screens

If you have a partial already in the view folder called _edit_within_form.html.erb, it with get included within the edit form.
If you have a partial already in the view folder called _new_within_form.html.erb, it with get included within the new form.
For these, you can use any of the objects by local variable name or the special f local variable to access the form itself.

These partials are good for including extra functionality in the form, like interactive widgets or hidden fields.
If you have a partial already in the view folder called _edit_after_form.html.erb, it with get included after the edit form.
If you have a partial already in the view folder called _new_after_form.html.erb, it with get included after the new form.
You can use any of the objects by local variable name (but you cannot use the form object f because it is not in scope.)

The within partials should do operations within the form (like hidden fields), and the after partials should do entirely unrelated operations, like a different form entirely.

These automatic pickups for partials are detected at buildtime. This means that if you add these partials later, you must rebuild your scaffold.

Related Sets

21 Nov 17:08
6ee745d
Compare
Choose a tag to compare

Used to show a checkbox set of related records. The relationship should be a has_and_belongs_to_many or a has_many through: from the object being built.

Consider the classic example of three tables: users, user_roles, and roles

User has_many :user_roles; UserRole belongs_to :user and belongs_to :role; and Role has_many :user_roles and has_many :user, through: :user_roles

We'll generate a scaffold to edit the users table. A checkbox set of related roles will also appear to allow editing of roles. (In this example, the only field to be edited is the email field.)

rails generate hot_glue:scaffold User --related-sets=roles --include=email,roles --gd

Note that when making a scaffold like this, you may leave open a privileged escalation attack (a security vulnerability).

To fix this, you'll need to use Pundit with special syntax designed for this purpose.

For a complete solution, please see Example 17 in the Hot Glue Tutorial.

Without Pundit, due to a quirk in how this code works with ActiveRecord, all update operations to the related sets table are permitted (and make edits to the related records), even if the update operation otherwise fails validation for the fields on the object. (ActiveRecord doesn't seem to have a way to validate the related sets directly.)

In this case, your update actions may update the related sets table but fail to update the current object.

Using this feature with Pundit will fix this problem, and it is achieved with an implementation that performs a pre-check for each related set against the Pundit policy.

hg-17A-2

Typeahead tweaks

14 Nov 01:33
319b98f
Compare
Choose a tag to compare

Searching - Typeahead Associations

03 Nov 18:19
05a17b2
Compare
Choose a tag to compare

The 0.6.x line now begins Hot Glue's foray into searching.

This first stab tackles how to handle foreign keys on the new and edit views only, when looking up a foreign key. Normally foreign keys (associations) are display as drop-downs. You can now use a typeahead when editing any foreign key.

Instead of displaying the foreign key in a drop-down list, the associated record is now selectable from a searchable typehead input.

The typeahead is implemented with a native Stimulus JS pair of controllers and is a modern & clean replacement to the old typeahead options.

  1. As a one-time setup step for your app, run
    bin/rails generate hot_glue:typeahead_install
  2. When generating a scaffold you want to make a typeahead association, use --modify='parent_id{typeahead}' where parent_id is the foreign key
    bin/rails generate hot_glue:scaffold Book --include=title,author_id --modify='author_id{typeahead}'
  3. Within each namespace, you will generate a special typeahead controller (it exists for the associated object to be searched on
    bin/rails generate hot_glue:typeahead Author
    This will create a controller for AuthorsTypeaheadController that will allow text search against any string field on the Author model.
    This special generator takes flags --namespace like the normal generator and also --search-by to let you specify the list of fields you want to search by.

The example Books & Authors app with typeahead is here:

https://github.com/hot-glue-for-rails/BooksAndAuthorsWithTypeahead2

Remember, this typeahead applies only to associations. You can use this feature only on new & edit. You cannot use this feature to search against the list page. Future versions of the 0.6.x line will apply search paradigms to the list page itself.

Hot Glue books and authors with typeahead

Various fixes

23 Oct 11:28
950de58
Compare
Choose a tag to compare

Various fixes:

  • fixed alert classes for error input for bootstrap 5 (changes to alert alert-danger was just alert-danger; todo: this should be abstracted into LayoutStrategy::Bootstrap)
  • switches to use a self-defined instance var @action instead of action_name; this is so I can
    switch it back to 'new' or 'edit' upon a failure re-display to have the view behave the expected way
  • fix in create.turbo_stream.erb for failure redisplay (was not working)
  • fixes syntax error (in generated code) in edit.erb when there was a nested set