【发布时间】:2012-08-04 07:18:12
【问题描述】:
Rails 路由器和表单生成器有一点问题。 我的应用程序具有模型和控制器的命名空间模块。模块用于更容易抽象到其他项目。
我使用routes.rb 范围方法而不是命名空间,因为我没有“丑陋”的路径助手。
看起来像:
scope module: :taxonomy do
resources :taxonomies do
resources :terms
end
end
问题是当我想编辑分类时(url:taxonomies/1/edit)我得到一个错误:
undefined method `taxonomy_taxonomy_path'
因为我的路线只是taxonomy_path
有什么方法可以到达form_for @taxonomy 以识别该路由是作用域的?不使用 form_for @taxonomy, url: taxonomy_path(@taxonomy) 是无法治愈的。因为respond_with @taxonomy 中控制器方法中的@taxonomy 对象总是引用taxonomy_taxonomy_url
我的模型:
module Taxonomy
class Taxonomy < ActiveRecord::Base
has_many :taxonomy_terms, inverse_of: :taxonomy
has_many :terms, through: :taxonomy_terms
class Term < ActiveRecord::Base
has_one :taxonomy_term, inverse_of: :term
has_one :taxonomy, through: :taxonomy_term
和控制器:
module Taxonomy
class TaxonomiesController < ApplicationController
【问题讨论】:
标签: ruby-on-rails namespaces routes nested-routes