8000 Make posts a nested resource (#5814) · activeadmin/activeadmin@6826c47 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6826c47

Browse files
deivid-rodriguezjavierjulio
authored andcommitted
Make posts a nested resource (#5814)
So we have an example of a nested resource in our test application.
1 parent 7e3eb6e commit 6826c47

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

spec/support/templates_with_data/admin/posts.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
ActiveAdmin.register Post do
22
permit_params :custom_category_id, :author_id, :title, :body, :published_date, :position, :starred, taggings_attributes: [ :id, :tag_id, :name, :position, :_destroy ]
33

4+
belongs_to :user
5+
46
includes :author, :category, :taggings
57

68
scope :all, default: true
@@ -23,7 +25,7 @@
2325

2426
batch_action :set_starred, form: { starred: :checkbox } do |ids, inputs|
2527
Post.where(id: ids).update_all(starred: inputs['starred'].present?)
26-
redirect_to collection_path, notice: "The posts have been updated."
28+
redirect_to collection_path(user_id: params["user_id"]), notice: "The posts have been updated."
2729
end
2830

2931
index do
@@ -57,7 +59,7 @@
5759
end
5860

5961
action_item :toggle_starred, only: :show do
60-
link_to 'Toggle Starred', toggle_starred_admin_post_path(post), method: :put
62+
link_to 'Toggle Starred', toggle_starred_admin_user_post_path(post.author, post), method: :put
6163
end
6264

6365
show do |post|

spec/support/templates_with_data/admin/users.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
paginated_collection(user.posts.includes(:category).order(:updated_at).page(params[:page]).per(10), download_links: false) do
3232
table_for(collection) do
3333
column :id do |post|
34-
link_to post.id, admin_post_path(post)
34+
link_to post.id, admin_user_post_path(post.author, post)
3535
end
3636
column :title
3737
column :published_date
@@ -42,7 +42,7 @@
4242
end
4343

4444
para do
45-
link_to "View all posts", admin_posts_path('q[author_id_eq]' => user.id)
45+
link_to "View all posts", admin_user_posts_path(user)
4646
end
4747
end
4848
end

0 commit comments

Comments
 (0)
0