Hot Glue Versions Save

Rapid scaffold builder for Turbo-Rails and Hotwire. Get the tutorial now at:

v0.6.3.2

2 months ago

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

4 months ago

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

4 months ago

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.

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

5 months ago

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.

v0.6.1

5 months ago

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

v0.6.0.1

6 months ago

32ddb222-2862-468d-b2d2-a5229240e2f3

v0.6.0

6 months ago

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

v0.5.26

6 months ago

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

v0.5.25

7 months ago
  • Fixes scoping on Pundit-built controllers; even when using pundit we should still wrap to the current build's own ownership scope (#132
  • don't write to the nav file if we're building a nested controller (#134)
  • adds system specs for self-auth feature
  • Pagination Fixes:

A new flag --paginate-per-page-selector (default false) will allow you to show a small drop-down to let the user choose 10, 25, or 100 results per page.

To get pagination to work, choose either #1 OR #2 below. #1 will replace the templates in app/views/kaminari so don't do that if you have modified them since first generating them out of Kaminari.

Option 1: Remove kaminari views and re-install them (bootstrap 4 or 5), setting data-turbo-action to advance to make Turbo move between pages with browser history

rm -rf app/views/kaminari
rails g kaminari:views bootstrap4
sed -i '' -e "s/class: 'page-link',/class: 'page-link', 'data-turbo-action': 'advance'/g" app/views/kaminari/_first_page.html.erb app/views/kaminari/_gap.html.erb app/views/kaminari/_last_page.html.erb app/views/kaminari/_next_page.html.erb app/views/kaminari/_page.html.erb app/views/kaminari/_prev_page.html.erb 

Option #2. Go into app/views/kaminari/ and modify each template in this folder by adding 'data-turbo-action': 'advance' to all of the links (which mostly appear in this code as the link_to_unless helper-- add the parameter onto the end of the calls to those helpers.)

With these upgrades, notice that

  1. when you navigate from page to page, the browser history is correctly replaced with ?page=2, ?page=3, etc
  2. There is a selector that allows the user to set the default result set size.

hg-v0-5-25-1

v0.5.24

7 months ago
  • TinyMCE implementation. See 'TinyMCE' in the README. Note: I also plan to implement ActionText as an alternative. However, because TinyMCE is implemented with a text field type an ActionText is implemented with a Rails-specific rich_text field type, the two mechanisms will be incompatible with one another. TinyMCE has an annoying drawback in how it works with Turbo refreshes (not very consistently), and style of loading Javascript is discordant with Rails moving forward. So I am leaving this implementation as experimental.
  • Spec Savestart code: In the behavior specs, there is a code marker (start & end) where you can insert custom code that gets saved between build. The start code maker has changed from #HOTGLUE-SAVESTART to # HOTGLUE-SAVESTART and the end code marker has changed from #HOTGLUE-END to # HOTGLUE-END. This now conforms to Rubocop. Be sure to do find & replace in your existing projects to keep your custom code.
  • Fix for specs for attachment fields. If you have attachments fields, you must have a sample file at spec/fixtures/glass_button.png
  • Pundit now correctly protects the index action (authorize was missing before)