1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Show object ids in scaffold pages when displaying referenced objects

Resolve Issue#29200

When scaffolding a model that references another model the
generated show and index html pages display the object directly
on the page. Basically, it just shows a memory address. That is
not very helpful. In this commit we show the object's id rather
than the memory address.

This updates the scaffold templates and the json builder files.
This commit is contained in:
Rasesh Patel 2017-05-24 01:34:07 -04:00
parent 99c87ad247
commit ecb2850a04
4 changed files with 20 additions and 5 deletions

View file

@ -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`).

View file

@ -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>

View file

@ -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 -%>

View file

@ -435,8 +435,8 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
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/
@ -449,7 +449,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
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
@ -457,6 +457,16 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
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