Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize scaffold generator #41210

Merged
merged 99 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
c696fd7
Slim down scaffold css
dhh Jan 22, 2021
22a8872
Use a box-style partial rather than a table
dhh Jan 22, 2021
cb1b5ce
Correct use of quotes
dhh Jan 22, 2021
a59d64c
Use modern array-of-strings declaration
dhh Jan 22, 2021
3d495b0
Use double quotes for everything
dhh Jan 22, 2021
fb4b549
Fix syntax
dhh Jan 22, 2021
1ac2745
Remove outdated viewport declaration
dhh Jan 22, 2021
e99ec71
Use double quotes everywhere
dhh Jan 22, 2021
63b2ca2
Use symbols not strings for before_action scoping
dhh Jan 24, 2021
74f3a28
Use human name to deal with double word records
dhh Jan 24, 2021
52e5f15
Grab test fixes from #41219
dhh Jan 24, 2021
d0f2b3f
Fix tests
dhh Jan 24, 2021
46a36d7
Use locar var not ivar
dhh Jan 24, 2021
9482270
Fix capitalization change
dhh Jan 24, 2021
b9cca44
Update railties/lib/rails/generators/rails/app/templates/app/views/la…
dhh Jan 24, 2021
91147ee
Update railties/test/generators/scaffold_controller_generator_test.rb
dhh Jan 24, 2021
651914e
Update railties/test/generators/scaffold_controller_generator_test.rb
dhh Jan 24, 2021
900cba0
Fix test
dhh Jan 24, 2021
1361075
Update railties/test/generators/scaffold_generator_test.rb
dhh Jan 28, 2021
91d74b6
Correct logic warning about initializers
gmcgibbon Jan 16, 2021
e979780
Rename master to main in all code references
rafaelfranca Jan 19, 2021
1fe64ee
Use length == 0 instead of empty in Preloader
jhawthorn Jan 19, 2021
ecbb688
Add regression tests for preloader query count
jhawthorn Jan 19, 2021
b456bac
ActionCable guides suggest test adapter for test env [ci skip]
santib Jan 19, 2021
0593d55
Changing 'rails new' --master to be --main
MikeRogers0 Jan 19, 2021
bef0f43
I think passing in the --master argument to run_generator is the way …
MikeRogers0 Jan 19, 2021
4adb2fb
Removing .count to figure out why its failing
MikeRogers0 Jan 19, 2021
c60040c
Raise unknown type error on the definition time
kamipo Jan 19, 2021
b63dd82
Refactor `attribute` not to reference `&block`
kamipo Jan 20, 2021
eb51999
Use major + minor AR versions in 'Directly inheriting' error message
radar Jan 15, 2021
ff0f158
Raise error when passing passing a class to :source_type
intrip Jan 20, 2021
762df3f
Adding badges and logo to README and CONTRIBUTING page
guillaumebriday Jan 18, 2021
c164172
switch references to main branch in docs
hummusonrails Jan 16, 2021
7c516bf
Updating references to /rails/blob/master & raiks/tree/master to poin…
MikeRogers0 Jan 16, 2021
f6f10d7
Don't return query cache enabled pools in the query cache executor
kamipo Jan 20, 2021
bd9aab9
Remove trailing commas in advanced route constraints example
Jan 21, 2021
14cb3a9
Search for yarn.cmd and yarn.ps1 in bin/yarn
jonathanhefner Jan 21, 2021
b4779d4
Run bin/yarn via Ruby
jonathanhefner Jan 21, 2021
21c5eb8
Allow to opt-out of `strict_loading` mode on a per-record base.
ayrton Jan 19, 2021
4447596
Fix granular connection swapping when there are multiple abstract cla…
eileencodes Jan 19, 2021
89c1122
Avoid testing Thor internals
jonathanhefner Jan 21, 2021
0ad4761
Fix the benchmark script to point to the main branch
rafaelfranca Jan 21, 2021
fd742e2
Resolve default annotation tags after config loads
jonathanhefner Jan 21, 2021
fbd602e
Upgrade all the gems to make sure we are testing with the latest vers…
rafaelfranca Jan 21, 2021
7b8c237
Don't bother checking if strings respond to string methods
shioyama Oct 15, 2020
07bedbc
Update name of input to fix typo
ttilberg Jan 22, 2021
a5a2a72
`connected_to` shouldn't be called on the abstract class that not est…
alpaca-tc Jan 6, 2021
fd71435
Add Webpacker to Guides list
ghiculescu Jan 18, 2021
37c1e2b
Update documents.yaml
fxn Jan 22, 2021
e015754
Fix unintialized instance variable connection_class
eileencodes Jan 22, 2021
a40f271
Webpacker guide: remove Basecamp reference [docs]
ghiculescu Jan 19, 2021
c73f29f
fix broken link
ghiculescu Jan 19, 2021
ea527fb
Update webpacker.md
ghiculescu Jan 19, 2021
ccac38d
Added the unless-block for continuity
ijlee2 Jan 20, 2021
579dd34
Added :status for continuity
ijlee2 Jan 20, 2021
1cb335b
Removed line for continuity
ijlee2 Jan 20, 2021
8802a87
Added a new line after the include statement
ijlee2 Jan 22, 2021
b089b48
Connection specification now passes the "url" key to the adapter
malomalo Jan 16, 2021
65393f8
Support hash config for `structure_dump_flags` and `structure_load_fl…
Aguardientico Jan 22, 2021
776f988
Update test docs in "contributing to Rails" guide
ghiculescu Jan 19, 2021
216c155
Fix current_page? with kwargs on ruby3
intrip Jan 21, 2021
31a909c
`start_with?` allows multiple prefix values
kamipo Jan 23, 2021
d9886a5
Fix code block in Webpacker Guide [ci skip]
houhoulis Jan 24, 2021
8c55224
Remove wrong usage for `arel_table` [ci skip]
kamipo Jan 24, 2021
c968bbf
Restore ActiveStorage::Blob#find_signed
composerinteralia Jan 24, 2021
a6e0605
Handle throwing in controller action in log subscriber
janko Jan 23, 2021
6a5fd29
Improve Fixture support for Active Storage (#41065)
seanpdoyle Jan 24, 2021
6216346
Improve ActionText::FixtureSet documentation (#41062)
seanpdoyle Jan 24, 2021
752a169
Fix Flaky ActiveStorage test (#41225)
seanpdoyle Jan 24, 2021
24c992a
Fix doc: stylesheet_include_tag -> stylesheet_link_tag
andrehjr Jan 23, 2021
fe5a34a
Remove reference to globalize gem
yboulkaid Jan 24, 2021
1ab1669
Fix typo [ci skip]
orhantoy Jan 25, 2021
d728737
Add small improvements to the Webpacker guide
davidstosik Jan 19, 2021
3207bb6
Fixing delegated types example.
andrewculver Jan 25, 2021
b5bb707
Allow jobs to rescue all exceptions
etiennebarrie Jan 22, 2021
ab87cf5
Guides: Missing erb tags for stylesheet_pack_tag [ci skip]
t27duck Jan 24, 2021
94203cc
Guides: Remove unneeded statement about stylesheet_pack_tag [ci skip]
t27duck Jan 25, 2021
d3236f8
Update test names to match their behaviour
samjewell Jan 25, 2021
92e5469
Remove SET NAMES, set collation using variable
robinroestenburg Jan 25, 2021
6acd284
Update test helper to call parallelize according to fork support
bjfish Jan 25, 2021
3c6eebc
Show a warning when running no migration using SCOPE
intrip Jan 25, 2021
fb560a2
Move ActiveStorage fixture hooks to on_load
seanpdoyle Jan 24, 2021
df247e6
Improve ActiveRecord strict_loading documentation
cveneziani Jan 24, 2021
da168a8
Remove legacy media=screen default from stylesheet_link_tag.
andrehjr Jan 22, 2021
4aa259d
Do not eagerly load Request before initializers
rafaelfranca Jan 26, 2021
db71539
Change Request#media_type to return nil
rafaelfranca Jan 26, 2021
8fafc97
`ActionDispatch::Request#content_type` now returned Content-Type head…
rafaelfranca Jan 26, 2021
d90c714
Disable rubocop suggestions
rafaelfranca Jan 26, 2021
acc08f1
Fix typo in the CHANGELOG
rafaelfranca Jan 26, 2021
e2b6679
Add config.action_view.stylesheet_media_default to baseline config
rafaelfranca Jan 27, 2021
af8c4ec
Rename the config to make clear it is a boolean
rafaelfranca Jan 27, 2021
0bc559e
Add CHANGELOG entry for #41215
rafaelfranca Jan 27, 2021
53fdc46
Fix CI failure due to `app.config.action_view.delete(:apply_apply_sty…
kamipo Jan 27, 2021
d6925af
Fix deprecation message s/Rails 6.1 will return/Rails 7.0 will return/
kamipo Jan 27, 2021
7a19e97
Revert "Merge pull request #41192 from kamipo/dont_return_pools"
eileencodes Jan 27, 2021
1ce7c6e
Revert "Merge pull request #41046 from eileencodes/dont-check-if-qc-i…
eileencodes Jan 27, 2021
6376355
Ensure test rake commands run immediately
etiennebarrie Jan 15, 2021
f0bff35
Fix typo
st0012 Jan 28, 2021
6c51242
Merge branch 'main' into modernize-scaffold
dhh Feb 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

```ruby
class User < ApplicationRecord
has_many :bookmarks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The association was used below to demonstrate usage of strict_loading on a Model. Is the removal intentional or removed by mistake while rebasing the PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mistake, adding back

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raised a PR for it: #41329. Please feel free to close it if you have added the change back 😊

has_many :articles, strict_loading: true
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def copy_view_files
template filename, File.join("app/views", controller_file_path, filename)
end
end

template "partial.html.erb", File.join("app/views", controller_file_path, "_#{singular_table_name}.html.erb")
end

private
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<h1>Editing <%= singular_table_name.titleize %></h1>
<h1>Editing <%= human_name.downcase %></h1>

<%%= render 'form', <%= singular_table_name %>: @<%= singular_table_name %> %>
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>

<%%= link_to 'Show', @<%= singular_table_name %> %> |
<%%= link_to 'Back', <%= index_helper %>_path %>
<br>

<div>
<%%= link_to "Show this <%= human_name.downcase %>", @<%= singular_table_name %> %> |
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper %>_path %>
</div>
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
<p id="notice"><%%= notice %></p>

<h1><%= plural_table_name.titleize %></h1>
<h1><%= human_name %></h1>

<table>
<thead>
<tr>
<% attributes.reject(&:password_digest?).each do |attribute| -%>
<th><%= attribute.human_name %></th>
<% end -%>
<th colspan="3"></th>
</tr>
</thead>
<div id="<%= plural_table_name %>">
<%%= render @<%= plural_table_name %> %>
</div>

<tbody>
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
<tr>
<% attributes.reject(&:password_digest?).each do |attribute| -%>
<td><%%= <%= singular_table_name %>.<%= attribute.column_name %> %></td>
<% end -%>
<td><%%= link_to 'Show', <%= model_resource_name %> %></td>
<td><%%= link_to 'Edit', edit_<%= singular_route_name %>_path(<%= singular_table_name %>) %></td>
<td><%%= link_to 'Destroy', <%= model_resource_name %>, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<%% end %>
</tbody>
</table>

<br>

<%%= link_to 'New <%= singular_table_name.titleize %>', new_<%= singular_route_name %>_path %>
<%%= link_to "New <%= human_name.downcase %>", new_<%= singular_route_name %>_path %>
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<h1>New <%= singular_table_name.titleize %></h1>
<h1>New <%= human_name.downcase %></h1>

<%%= render 'form', <%= singular_table_name %>: @<%= singular_table_name %> %>
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>

<%%= link_to 'Back', <%= index_helper %>_path %>
<br>

<div>
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper %>_path %>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div id="<%%= dom_id <%= singular_table_name %> %>" class="scaffold_record">
<% attributes.reject(&:password_digest?).each do |attribute| -%>
<p>
<strong><%= attribute.human_name %>:</strong>
<% if attribute.attachment? -%>
<%%= link_to <%= singular_table_name %>.<%= attribute.column_name %>.filename, <%= singular_table_name %>.<%= attribute.column_name %> if <%= singular_table_name %>.<%= attribute.column_name %>.attached? %>
<% elsif attribute.attachments? -%>
<%% <%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
<div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
<%% end %>
<% else -%>
<%%= <%= singular_table_name %>.<%= attribute.column_name %> %>
<% end -%>
</p>

<% end -%>
<p>
<%%= link_to "Show this <%= human_name %>", <%= singular_table_name %> %>
</p>
</div>
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
<p id="notice"><%%= notice %></p>

<% attributes.reject(&:password_digest?).each do |attribute| -%>
<p>
<strong><%= attribute.human_name %>:</strong>
<% if attribute.attachment? -%>
<%%= link_to @<%= singular_table_name %>.<%= attribute.column_name %>.filename, @<%= singular_table_name %>.<%= attribute.column_name %> if @<%= singular_table_name %>.<%= attribute.column_name %>.attached? %>
<% elsif attribute.attachments? -%>
<%% @<%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
<div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
<%% end %>
<% else -%>
<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>
<% end -%>
</p>
<%%= render @<%= singular_table_name %> %>

<% end -%>
<%%= link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>) %> |
<%%= link_to 'Back', <%= index_helper %>_path %>
<div>
<%%= link_to "Edit this <%= human_name.downcase %>", edit_<%= singular_table_name %>_path(@<%= singular_table_name %>) %> |
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper %>_path %>

<%%= button_to "Destroy this <%= human_name.downcase %>", <%= singular_table_name %>_path(@<%= singular_table_name %>), method: :delete %>
dhh marked this conversation as resolved.
Show resolved Hide resolved
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
<html>
<head>
<title><%= camelized %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%%= csrf_meta_tags %>
<%%= csp_meta_tag %>

<%- if options[:skip_javascript] -%>
<%%= stylesheet_link_tag 'application' %>
<%%= stylesheet_link_tag "application" %>
<%- else -%>
<%- unless options[:skip_turbolinks] -%>
<%%= stylesheet_link_tag 'application', 'data-turbolinks-track': 'reload' %>
<%%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%%= stylesheet_link_tag "application", "data-turbolinks-track": "reload" %>
<%%= javascript_pack_tag "application", "data-turbolinks-track": "reload" %>
<%- else -%>
<%%= stylesheet_link_tag 'application' %>
<%%= javascript_pack_tag 'application' %>
<%%= stylesheet_link_tag "application" %>
<%%= javascript_pack_tag "application" %>
<%- end -%>
<%- end -%>
</head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,3 @@
body {
background-color: #fff;
color: #333;
margin: 33px;
}

body, p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}

pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}

a {
color: #000;
}

a:visited {
color: #666;
}

a:hover {
color: #fff;
background-color: #000;
}

th {
padding-bottom: 5px;
}

td {
padding: 0 5px 7px;
}

div.field,
div.actions {
margin-bottom: 10px;
Expand All @@ -46,6 +7,12 @@ div.actions {
color: green;
}

.scaffold_record {
border: 1px solid black;
padding: 10px;
margin-bottom: 10px;
}

.field_with_errors {
padding: 2px;
background-color: red;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require_dependency "<%= namespaced_path %>/application_controller"
<% end -%>
<% module_namespacing do -%>
class <%= controller_class_name %>Controller < ApplicationController
before_action :set_<%= singular_table_name %>, only: [:show, :update, :destroy]
before_action :set_<%= singular_table_name %>, only: %i[ show update destroy ]

# GET <%= route_url %>
def index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require_dependency "<%= namespaced_path %>/application_controller"
<% end -%>
<% module_namespacing do -%>
class <%= controller_class_name %>Controller < ApplicationController
before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
before_action :set_<%= singular_table_name %>, only: %i[ show edit update destroy ]

# GET <%= route_url %>
def index
Expand All @@ -29,7 +29,7 @@ class <%= controller_class_name %>Controller < ApplicationController
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>

if @<%= orm_instance.save %>
redirect_to <%= redirect_resource_name %>, notice: <%= "'#{human_name} was successfully created.'" %>
redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully created.") %>
else
render :new, status: :unprocessable_entity
end
Expand All @@ -38,7 +38,7 @@ class <%= controller_class_name %>Controller < ApplicationController
# PATCH/PUT <%= route_url %>/1
def update
if @<%= orm_instance.update("#{singular_table_name}_params") %>
redirect_to <%= redirect_resource_name %>, notice: <%= "'#{human_name} was successfully updated.'" %>
redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %>
else
render :edit, status: :unprocessable_entity
end
Expand All @@ -47,7 +47,7 @@ class <%= controller_class_name %>Controller < ApplicationController
# DELETE <%= route_url %>/1
def destroy
@<%= orm_instance.destroy %>
redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %>
redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %>
end

private
Expand Down
1 change: 1 addition & 0 deletions railties/test/application/generators_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def check_expected
app/views/posts/show.html.erb
app/views/posts/new.html.erb
app/views/posts/_form.html.erb
app/views/posts/_post.html.erb
test/controllers/posts_controller_test.rb
test/system/posts_test.rb
app/helpers/posts_helper.rb
Expand Down
2 changes: 1 addition & 1 deletion railties/test/application/rake_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class Hello
end

def test_code_statistics_sanity
assert_match "Code LOC: 74 Test LOC: 3 Code to Test Ratio: 1:0.0",
assert_match "Code LOC: 73 Test LOC: 3 Code to Test Ratio: 1:0.0",
rails("stats")
end

Expand Down
6 changes: 3 additions & 3 deletions railties/test/generators/app_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def test_skip_bundle
def test_assets
run_generator

assert_file("app/views/layouts/application.html.erb", /stylesheet_link_tag\s+'application', 'data-turbolinks-track': 'reload'/)
assert_file("app/views/layouts/application.html.erb", /javascript_pack_tag\s+'application', 'data-turbolinks-track': 'reload'/)
assert_file("app/views/layouts/application.html.erb", /stylesheet_link_tag\s+"application", "data-turbolinks-track": "reload"/)
assert_file("app/views/layouts/application.html.erb", /javascript_pack_tag\s+"application", "data-turbolinks-track": "reload"/)
assert_file("app/assets/stylesheets/application.css")
assert_file("app/javascript/packs/application.js")
end
Expand Down Expand Up @@ -667,7 +667,7 @@ def test_javascript_is_skipped_if_required
assert_no_file "app/javascript"

assert_file "app/views/layouts/application.html.erb" do |contents|
assert_match(/stylesheet_link_tag\s+'application' %>/, contents)
assert_match(/stylesheet_link_tag\s+"application" %>/, contents)
assert_no_match(/javascript_pack_tag\s+'application'/, contents)
end
end
Expand Down
2 changes: 1 addition & 1 deletion railties/test/generators/plugin_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def test_scaffold_generator_for_mountable_api_plugins

assert_file "app/models/bukkits/article.rb"
assert_file "app/controllers/bukkits/articles_controller.rb" do |content|
assert_match "only: [:show, :update, :destroy]", content
assert_match "only: %i[ show update destroy ]", content
end

assert_no_directory "app/assets"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,11 @@ def test_model_name_option
end

assert_file "app/views/admin/users/index.html.erb" do |content|
assert_match("'Show', [:admin, user]", content)
assert_match("'Edit', edit_admin_user_path(user)", content)
assert_match("'Destroy', [:admin, user]", content)
assert_match("'New User', new_admin_user_path", content)
assert_match("\"New user\", new_admin_user_path", content)
end

assert_file "app/views/admin/users/new.html.erb" do |content|
assert_match("'Back', admin_users_path", content)
assert_match("\"Back to users\", admin_users_path", content)
end

assert_file "app/views/admin/users/_form.html.erb" do |content|
Expand Down Expand Up @@ -267,7 +264,7 @@ def test_api_only_generates_a_proper_api_controller
assert_match(/class UsersController < ApplicationController/, content)
assert_no_match(/respond_to/, content)

assert_match(/before_action :set_user, only: \[:show, :update, :destroy\]/, content)
assert_match(/before_action :set_user, only: %i\[ show update destroy \]/, content)

assert_instance_method :index, content do |m|
assert_match(/@users = User\.all/, m)
Expand Down