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
Scaffold generator's view points should point to the _id field of the reference #11573
Comments
|
@spastrino How can i know the currency_id while creating account? If there was select box of currencies, i can select one and that can have value which will be currency_id from database. But here, as it is textbox, i don't know what is the id of the currency. |
|
select box is fine too |
|
I wrote a test for this, but need feedback. Looks like Rails::Generators::NamedBase is where I want to look? Pointers? # railties/test/generators/scaffold_generator_test.rb
def test_scaffold_generator_belongs_to
run_generator ["account", "name", "currency:belongs_to"]
assert_file "app/models/account.rb", /belongs_to :currency/
assert_migration "db/migrate/create_accounts.rb" do |m|
assert_method :change, m do |up|
assert_match(/t\.string :name/, up)
assert_match(/t\.belongs_to :currency/, up)
end
end
assert_file "app/controllers/accounts_controller.rb" do |content|
assert_instance_method :account_params, content do |m|
assert_match(/permit\(:name, :currency_id\)/, m)
end
end
assert_file "app/views/accounts/_form.html.erb" do |content|
assert_match(/<%= f\.text_field :name %>/, content)
assert_match(/<%= f\.text_field :currency_id %>/, content)
end
end |
|
You have to look at attributes https://github.com/rails/rails/blob/master/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb#L25 |
|
@spastorino same thing applies to |
|
right. They are aliases |
|
@rafaelfranca Thank you, I have a patch, submitting a PR now |
…in _form view [Fixes rails#11573]
|
@spastorino |
|
Thanks a lot @zzak may Rails be with you ;) |
I'm opening this easy to fix issue for people looking for easy things to fix :).
Steps to reproduce
And try to tie an account with a currency. The account view should be pointing to currency_id.
The text was updated successfully, but these errors were encountered: