Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Use Ids instead of memory addresses when displaying references in scaffold views
Fixes #29200.

*Rasesh Patel*

* Adds support for multiple databases to `rails db:migrate:status`.
Subtasks are also added to get the status of individual databases (eg. `rails db:migrate:status:animals`).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
<tr>
<% attributes.reject(&:password_digest?).each do |attribute| -%>
<td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<% attributes.reject(&:password_digest?).each do |attribute| -%>
<p>
<strong><%= attribute.human_name %>:</strong>
<%%= @<%= singular_table_name %>.<%= attribute.name %> %>
<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>
</p>

<% end -%>
Expand Down
16 changes: 13 additions & 3 deletions railties/test/generators/scaffold_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ def test_scaffold_generator_outputs_error_message_on_missing_attribute_type
end
end

def test_scaffold_generator_belongs_to
run_generator ["account", "name", "currency:belongs_to"]
def test_scaffold_generator_belongs_to_and_references
run_generator ["account", "name", "currency:belongs_to", "user:references"]

assert_file "app/models/account.rb", /belongs_to :currency/

Expand All @@ -449,14 +449,24 @@ def test_scaffold_generator_belongs_to

assert_file "app/controllers/accounts_controller.rb" do |content|
assert_instance_method :account_params, content do |m|
assert_match(/permit\(:name, :currency_id\)/, m)
assert_match(/permit\(:name, :currency_id, :user_id\)/, m)
end
end

assert_file "app/views/accounts/_form.html.erb" do |content|
assert_match(/^\W{4}<%= form\.text_field :name %>/, content)
assert_match(/^\W{4}<%= form\.text_field :currency_id %>/, content)
end

assert_file "app/views/accounts/index.html.erb" do |content|
assert_match(/^\W{8}<td><%= account\.name %><\/td>/, content)
assert_match(/^\W{8}<td><%= account\.user_id %><\/td>/, content)
end

assert_file "app/views/accounts/show.html.erb" do |content|
assert_match(/^\W{2}<%= @account\.name %>/, content)
assert_match(/^\W{2}<%= @account\.user_id %>/, content)
end
end

def test_scaffold_generator_database
Expand Down