0
我正在爲我的運動隊製作一個網站,供玩家發佈博客文章。Rails:一對多參數
class Player < ApplicationRecord
has_many :blogs, dependent: :destroy
end
class Blog < ApplicationRecord
belongs_to :player
end
我的問題是:
是什麼設置了以下兩個參數的路由/控制器動作之間的區別?他們都給我完全一樣的東西。
1)
路線:
get "players/:player_id/posts" => "blogs#show", as: "player_posts"
控制器動作:
class BlogsController < ApplicationController
def show
@player = Player.find(params[:player_id])
@blogs = @player.blogs
end
end
2)
路線:
get "players/:id/posts" => "blogs#show", as: "player_posts"
控制器動作:
class BlogsController < ApplicationController
def show
@player = Player.find(params[:id])
@blogs = @player.blogs
end
end