Commit Graph

7583 Commits

Author SHA1 Message Date
Jonathan Hefner
840ecf1e96
Merge pull request #44508 from jonathanhefner/apidocs-format-application-booting-process
Fix formatting of "Booting process" section [ci-skip]
2022-02-23 12:07:56 -06:00
Hartley McGuire
67b9347c16 use git init -b in generator when supported
This has the benefit of hiding the warning message from git when
initialBranch configuration is unset, and was a recommendation on the
original commit adding main as the default branch for generators.

Ref: eb261937ac856100b4e1c8a2dbb56aab6e5d140e
2022-02-22 11:05:46 -05:00
Jonathan Hefner
fe3fc94eb0 Fix formatting of "Booting process" section [ci-skip]
Rendering the list of boot steps as a code block confused the syntax
highlighter.

This commit changes the list to use RDoc's ordered list syntax, and adds
inline code markup as appropriate.
2022-02-21 11:45:19 -06:00
Jonathan Hefner
a801aa7cde Mark up inline code [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner
e37adfed4e Add Oxford commas [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner
5fdbd217d1 Fix typos [ci-skip] 2022-02-21 11:11:11 -06:00
Matthew Draper
ad0f0e6980 Be explicit every time we invoke 'rails'
This almost never matters, but if the path-global 'rake' or 'rails'
points to a specific (and wrong) ruby version, (or, possible in CI,
there is no installed 'rails' executable), things get confused.

Instead, any time we mean "run a global 'rails', as for 'new'", use a
fully-qualified path to our in-tree copy. And any time we're working
inside an application, use the bin/rails script directly. It would be
equivalently valid to always use the one in exe/, because that handles
searching for bin/rails internally... but it's uglier to fully-qualify,
plus 'rake' would then be more complicated.
2022-02-22 00:54:10 +10:30
Eddie Lebow
935cc1b10c
Document horo variables in RDoc configuration
https://github.com/zzak/sdoc/blob/master/lib/rdoc/generator/template/rails/class.rhtml
2022-02-18 16:45:21 -05:00
Petrik
7118ebabbb Fix rdoc for session_store documentation [ci-skip]
Use + instead of ` for values to pass.
2022-02-17 19:12:16 +01:00
Petrik
7c7d0b5ef1 Document some methods in Application::Configuration [ci-skip]
The documentation was mostly copied from the configurations
guide.
2022-02-16 21:07:40 +01:00
Gannon McGibbon
965367e390
Merge pull request #44393 from Edouard-chin/ec-class-module-children
Add module/class nesting consistency on newly generated application:
2022-02-10 15:51:10 -05:00
Edouard CHIN
5875c68209 Add module/class nesting consistency on newly generated application:
- These two generated files are the only two that uses a compact style
  when defining a class, (it's not the case for their non-test
  counterpart i.e. 0f3642596f/railties/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb.tt (L1-L2)).

  This fixes that to add some consistency and will avoid users using
  rubocop with the `Style/ClassAndModuleChildren: nested` rule to have
  to manually edit those files when generating a new app.
2022-02-10 20:02:36 +01:00
Rafael Mendonça França
de7c495209
Merge pull request #44354 from rails/to-fs-as-the-primary
Make #to_fs the default replacement for #to_s(:format)
2022-02-08 11:50:24 -05:00
Zack
5d0c2b0dd2 Change MessageEncryptor default serializer to JSON for Rails 7.1
These changes include adding a hybrid serializer class
named JsonWithMarshalFallback in order for existing apps
to have an upgrade path from Marshal to JSON.
2022-02-07 12:19:36 -05:00
David Heinemeier Hansson
41478f7074 Make #to_fs the default replacement for #to_s(:format)
#to_formatted_s is too cumbersome.
2022-02-07 12:41:21 +01:00
Jean Boussier
4f12bcd7f1 Remove the deprecated urlsafe_csrf_tokens configuration
Ref: https://github.com/rails/rails/pull/43817

Normally we remove deprecated code much later, but in this case
it's in the way of https://github.com/rails/rails/pull/44283
so I think it would make sense to remove it now.
2022-02-01 10:35:43 +01:00
Henrik Nyh
e87608e355 Use safer 'destroy!' in controller scaffolds
The old code does

    @foo.destroy
    redirect_to foo_url, notice: "Foo was successfully destroyed."

which would incorrectly state the record was destroyed even if prevented
by a `before_destroy` callback.

The new version would raise.
2022-01-20 16:46:07 +00:00
Ryuta Kamizono
dc7bb3aa7e
Merge pull request #44144 from p8/railties/csp-cleanup
Clean up initializer templates [ci-skip]
2022-01-11 20:48:52 +09:00
Jean Boussier
b6987d6e14
Merge pull request #44133 from Shopify/strip-load-path-by-default
Disable config.add_autoload_paths_to_load_path by default in Rails 7.1
2022-01-11 12:12:08 +01:00
Petrik
7d5afb6c0c Clean up initializer templates [ci-skip]
Add some missing punctuation marks and make permissions_policy more
consistent with other initializers.
Also rename the `f` variable to the more clearer `policy` similar to
content_security_policy.rb.
2022-01-11 12:07:43 +01:00
Jean Boussier
a191321f7b Disable config.add_autoload_paths_to_load_path by default in Rails 7.1
Ref: 668673f779

Now that Zeitwerk is the only autoloader, there no reason
to add autoloaded paths to `$LOAD_PATH`.
2022-01-11 12:05:32 +01:00
Eddie Lebow
9fef0c9658
Expand filter_parameter_logging initializer template doc
on-behalf-of: @Cofense <oss@cofense.com>
2022-01-10 15:39:12 -05:00
Rafael Mendonça França
1d665e13a2
Merge pull request #44118 from JuanVqz/add-cursor-pointer
add cursor pointer when hovering rails logo in welcome page
2022-01-07 22:41:38 -05:00
Juan Vasquez
bf6cef2882 add cursor pointer when hovering rails logo in welcome page 2022-01-07 15:21:59 -06:00
Juan Vasquez
883da962de Add Ruby on Rails version on title 2022-01-07 15:08:55 -06:00
Jonathan Hefner
dfbc7af7bd Reorganize versioned default values [ci-skip]
There is still some confusion about how contributors should communicate
versioned default values.  Now that each configuration setting has its
own heading (since #43138), it seems appropriate that each setting's
section be self-contained.  Therefore, this commit moves each versioned
default value into its respective section.

This also adds a few configuration setting descriptions and baseline
default values that were missing.
2022-01-07 11:31:02 -06:00
Rafael Mendonça França
9188b49883
Merge pull request #43968 from sabljak/sabljak/remove-x-download-options
Remove X-Download-Options default header
2022-01-06 10:39:14 -05:00
Harun Sabljaković
486be06ccb Remove X-Download-Options default header
Since X-Download-Options header is only used by the soon deprecated Internet Explorer, it makes sense to remove this header as a default one.
2022-01-06 10:03:17 +01:00
Jonathan Hefner
18880323f0 Prevent duplicate entries in plugin Gemfile
This commit refactors the plugin `Gemfile.tt` to abstract much of the
logic into the `gemfile_entries` helper.  Doing so avoids adding
duplicate `Gemfile` entries (e.g. `gem "sqlite3"`), as well as
application-only `Gemfile` entries (e.g. `gem "puma"`), when generating
a plugin with a prerelease flag (e.g. `--dev`).
2022-01-05 16:59:58 -06:00
Rafael Mendonça França
776b0ce256
Merge pull request #44016 from jonathanhefner/fix-plugin-dummy-asset-pipeline
Fix asset pipeline errors for plugin dummy apps
2022-01-05 17:47:49 -05:00
Jonathan Hefner
330becbdd0 Fix asset pipeline errors for plugin dummy apps
To fix #43920, f292daad7051275f7b557b352876cfeb3988f639 added
`sprockets-rails` to the generated `Gemfile` for engine plugins because
their dummy apps use Sprockets.  However, non-engine plugins exhibit the
same issue because their dummy apps also use Sprockets.

This commit forces `skip_asset_pipeline` to be true when a plugin is not
an engine, and fixes several tests that failed to detect these issues
because they were accidentally using the `rails/rails` `Gemfile` instead
of the generated plugin `Gemfile`.
2022-01-05 15:50:43 -06:00
Rafael Mendonça França
f9761739a3
Merge pull request #43984 from jonathanhefner/fix-route-action-revocation
Fix generated route revocation
2022-01-05 15:47:20 -05:00
Xavier Noria
761eeb1005 Update module definition style 2022-01-05 20:47:22 +01:00
Xavier Noria
9b61af8179 Delay loading Zeitwerk 2022-01-05 12:59:49 +01:00
Jonathan Hefner
724a998110 Fix generated route revocation
Follow-up to #41584.

Thor uses a regexp with its own capture groups when revoking an
`inject_into_file` call.  Thus an `:after` regexp containing capture
groups will interfere with Thor's regexp.

This commit changes the `:after` regexp we pass to `inject_into_file`
so that it no longer contains capture groups.  This commit also cleans
up any newly-empty namespace blocks when revoking a route, since
`inject_into_file` does not handle that.

The majority of this commit is refactoring and clean-up.  The actual
regexp fix is just the following line:

```ruby
namespace_pattern = /#{Regexp.escape namespace_match.to_s}/
```

Fixes #43950.
2021-12-24 11:55:39 -06:00
Rafael Mendonça França
1438c0416f
Keep the comments in the generate application consistent 2021-12-20 23:35:14 +00:00
Rafael Mendonça França
f292daad70
Make sure plugin generator works with dummy app
The dummy app is using sprockets, so we need to include sprocket-rails
if the sprockets is not skipped.

Fixes #43920.
2021-12-20 22:14:56 +00:00
eileencodes
b96d01bb1b
Fix dbconsole for 3-tier config.
It's possible that applications using a 3-tier config don't have a
"primary" database entry. When booting the db console we should take the
first database, not assume there's a primary.

This also changes the message to be more clear. If no database is
provided and there are no databases for the environment we shouldn't
say that "primary" didn't exist - instead it should say no databases
exist.
2021-12-17 11:17:17 -05:00
Aaron Patterson
faf3a86028
Merge pull request #43871 from rails/rm-fix-hosts-with-port
Allow any allowed host with port
2021-12-15 11:48:32 -08:00
Jonathan Hefner
ea15f8e6df Fix scaffold index.html.erb variable name
Due to a conflict between #43846 and #43611, the variable name generated
inside the `each` block did not match the block parameter name for
namespaced models.  For example, if the block parameter name was
`admin_role`, the variable name inside the block would be just `role`.

This commit changes `index.html.erb` to use the correct variable name,
and adds much more test coverage.

This commit also changes the target for the "Destroy" button rendered
in `show.html.erb` from a route helper call to a bare model reference,
e.g. from `admin_role_path(@admin_role)` to just `@admin_role`.  This
was missed in #43611.
2021-12-15 12:35:50 -06:00
Rafael Mendonça França
c681aaba81
Allow any allowed host with port
All allowed host should be allowed if they are being accessed using a
port.

Fixes #43870.
2021-12-15 02:50:13 +00:00
Rafael Mendonça França
ab754e95d8
Merge pull request #43817 from etiennebarrie/deprecate-non-url-safe-csrf-tokens
Deprecate non-URL-safe CSRF tokens
2021-12-15 01:48:51 +00:00
Rafael Mendonça França
68f4fbc7cf
Merge pull request #43850 from hachi8833/fix_favicon_link_tag
Remove "shortcut" link type from favicon_link_tag method
2021-12-14 20:37:34 -05:00
Rafael Mendonça França
6cd75a42fa
Merge PR #43611
Squashed commit of the following:

    Tweaks

    Extend test adding more assertions

    Update scaffold generator test and add application generator test for controller generator with namespace

    Adapt code to feedback suggestions

    Apply suggestions from code review

    Run generated tests by scaffold controller generator

    Fix generated tests too

    Keep generated url helpers consistent

    Fix scaffold controller generator with namespace

    For example:

    ```
    bundle exec rails g scaffold_controller Admin::Post title:string content:text --model-name=Post
    ```

    It fixes the code generated by railties, other changes are required on
    jbuilder gem.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
Co-authored-by: José Galisteo <ceritium@gmail.com>
2021-12-15 01:29:07 +00:00
Rafael Mendonça França
0776c8bd51
Merge pull request #43846 from fig/fix-scaffold-self-referential-link
Move "show" link from partial to index template.
2021-12-14 20:24:18 -05:00
Rafael Mendonça França
52c0711bcf
Merge pull request #39663 from jonathanhefner/rails-new-prerelease
Run `rails new` using specified prerelease version
2021-12-14 20:11:55 -05:00
Rafael Mendonça França
16f026e15a
Merge pull request #43511 from seanpdoyle/active-storage-overwrite-many-with-emptyish
ActiveStorage: support empty attachments submits
2021-12-14 19:52:34 -05:00
David Heinemeier Hansson
64675160ab
Generated Gemfile will automatically pickup the latest version on first bundle (#43866)
* Generated Gemfile will automatically pickup the latest version on first bundle

No need to prescribe the lower boundary for a newly generated Gemfile, since the first bundle will automatically lock-in the latest version.

* Elevating floating entries with explaining factory method

* Trailing space
2021-12-14 15:47:59 -08:00
Sean Doyle
4f191b9754 ActiveStorage: support empty attachments submits
The background
---

Configuration for replacing a collection was introduced in
[rails/rails#36716][].

However, since [rails/rails#42596][] has been merged, Rails 7.1 and
beyond will default to _replacing_ an Active Storage `has_many_attached`
relationship, as opposed to _appending to it_.

The problem
---

With replacement as the established precedent, it's currently a
challenge to replace an existing collection with an empty one.

The solution
---

This commit makes two changes.

The first is to Action View and its form building helpers. The change
draws inspiration from how an `<input type="checkbox">` field (or
collection of fields) is paired with an `<input type="hidden">` field to
represent the unchecked value. The change pairs any `<input type="file"
multiple="multiple">` elements with an `<input type="hidden">` element
to represent an empty collection. Like the [check_box][] form builder
method, the `file_field`  method accepts an `include_hidden:` option to
skip the creation of the hidden element.

The second is to how Active Storage generates attribute assignment
methods through `has_many_attached`. With the possibility of an `<input
type="file">` field being paired with an `<input type="hidden"
value="">` field, the backing models need to be able to coerce an
"empty-ish" value into an empty list. For example:

```ruby
@user.highlights = [""]
@user.highlights        # => []
```

When combined, these changes enable consumer applications to submit
"empty" collections to blank out existing attachments.

Support is configured through the
`config.active_storage.multiple_file_field_include_hidden` configuration
value, which defaults to `false`.

[check_box]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-check_box
[rails/rails#36716]: https://github.com/rails/rails/pull/36716
[rails/rails#42596]: https://github.com/rails/rails/pull/42596
2021-12-14 18:40:35 -05:00
Aaron Patterson
d02d566660
Merge pull request #43868 from rails/fix-default-hosts
Allow localhost with a port by default in development
2021-12-14 14:51:36 -08:00