Skip to content

Commit

Permalink
Merge pull request #2701 from loicginoux/pass_params_to_new
Browse files Browse the repository at this point in the history
pass parameters to new forms when model is namespaced
  • Loading branch information
mshibuya committed Feb 13, 2017
2 parents 7f42543 + 77edad9 commit bfdcf35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rails_admin/config/actions/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class New < RailsAdmin::Config::Actions::Base
@authorization_adapter && @authorization_adapter.attributes_for(:new, @abstract_model).each do |name, value|
@object.send("#{name}=", value)
end
if object_params = params[@abstract_model.to_param]
if object_params = params[@abstract_model.param_key]
sanitize_params_for!(request.xhr? ? :modal : :create)
@object.set_attributes(@object.attributes.merge(object_params.to_h))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@
is_expected.to have_selector("textarea#cms_basic_page_content[name='cms_basic_page[content]']")
end
end

describe 'GET /admin/cms_basic_page/new with parameters for pre-population' do
it 'populates form field when corresponding parameters are passed in' do
visit new_path(model_name: 'cms~basic_page', cms_basic_page: {title: 'Hello'})
expect(page).to have_css('input[value=Hello]')
end
end
end

0 comments on commit bfdcf35

Please sign in to comment.