Skip to content

Commit

Permalink
Fix permitted_param generation for belongs_to when :param is us…
Browse files Browse the repository at this point in the history
…ed (#6460)

When playing around with our sample application, I noticed that you
couldn't create post taggings due to this bug.
  • Loading branch information
deivid-rodriguez committed Sep 18, 2020
1 parent db1ac5a commit 9269851
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions features/belongs_to.feature
Expand Up @@ -50,6 +50,27 @@ Feature: Belongs To
When I press "Update Post"
Then I should see "Post was successfully updated."

Scenario: Updating a child resource page with custom configuration
Given a configuration of:
"""
ActiveAdmin.register User
ActiveAdmin.register Post do
belongs_to :author, class_name: "User", param: "user_id", route_name: "user"
permit_params :title
form do |f|
f.actions
end
end
"""
When I go to the last author's last post page
And I follow "Edit Post"
Then I should see the element "form[action='/admin/users/2/posts/2']"
And I should see a link to "Hello World" in the breadcrumb

When I press "Update Post"
Then I should see "Post was successfully updated."

Scenario: Creating a child resource page
Given a configuration of:
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/resource/belongs_to.rb
Expand Up @@ -46,7 +46,7 @@ def required?
end

def to_param
:"#{@target_name}_id"
(@options[:param] || "#{@target_name}_id").to_sym
end
end
end
Expand Down

0 comments on commit 9269851

Please sign in to comment.