【发布时间】:2021-08-27 14:26:41
【问题描述】:
因为我使用 Rails monolith 而不是 GrapeAPI 已经有一段时间了,所以我提出了一个愚蠢的问题。我想为路径创建一个路由 - users/portfolios/1/portfolio_reports/archived_reports,我将在其中显示 PortfolioReports.where(status: 'archived')。我创建了路线:
namespace :users do
resources :portfolios, only: [:index, :show] do
resources :archived_report, only: [:index, :show]
resources :portfolio_report, only: [:index, :show]
end
end
所以我有两个问题:路由文件应该看起来像我当前的 routes.rb 吗?如果我有如下的 Portfolio 和 PortfolioReport 模型,portfolio_reports_controller 应该在 app/controllers/users/portfolio_reports_controller.rb 或 app/controllers/portfolio_reports_controller.rb 内?
class Portfolio
has_many :portfolio_reports
end
class PortfolioReport
belongs_to :portfolio
end
【问题讨论】:
-
我不确定拥有像
users/portfolios/1/portfolio_reports/archived_reports这样的路径是否有意义。可以是users/1/portfolios/1/portfolio_reports/archived_reports还是portfolios/1/portfolio_reports/archived_reports -
现在它必须是
users/portfolios/1/portfolio_reports/archived_reports,但在不久的将来可能会是users/1/portfolios/1/portfolio_reports/archived_reports
标签: ruby-on-rails routes