Skip to content

Commit bfdcf35

Browse files
authored
Merge pull request #2701 from loicginoux/pass_params_to_new
pass parameters to new forms when model is namespaced
2 parents 7f42543 + 77edad9 commit bfdcf35

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/rails_admin/config/actions/new.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class New < RailsAdmin::Config::Actions::Base
2020
@authorization_adapter && @authorization_adapter.attributes_for(:new, @abstract_model).each do |name, value|
2121
@object.send("#{name}=", value)
2222
end
23-
if object_params = params[@abstract_model.to_param]
23+
if object_params = params[@abstract_model.param_key]
2424
sanitize_params_for!(request.xhr? ? :modal : :create)
2525
@object.set_attributes(@object.attributes.merge(object_params.to_h))
2626
end

spec/integration/basic/new/rails_admin_namespaced_model_new_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,11 @@
2727
is_expected.to have_selector("textarea#cms_basic_page_content[name='cms_basic_page[content]']")
2828
end
2929
end
30+
31+
describe 'GET /admin/cms_basic_page/new with parameters for pre-population' do
32+
it 'populates form field when corresponding parameters are passed in' do
33+
visit new_path(model_name: 'cms~basic_page', cms_basic_page: {title: 'Hello'})
34+
expect(page).to have_css('input[value=Hello]')
35+
end
36+
end
3037
end

0 commit comments

Comments
 (0)