命名空间 form_for 中的嵌套资源 [英] Nested resources in namespace form_for

查看:17
本文介绍了命名空间 form_for 中的嵌套资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

form_for 助手错误地确定了我在命名空间内嵌套资源的路径.有问题的模型分别是:Forum::ThreadForum::Reply,位于我的模型目录下名为forum"的子文件夹中.这是在 Rails 3 BETA 3 中.

The form_for helper incorrectly determines the path to my nested resource inside of a namespace. The models in question are: Forum::Thread and Forum::Reply respectively, located in a subfolder called "forum" under my models directory. This is in Rails 3 BETA 3.

routes.rb

  namespace :forum do
    root :to => 'threads#index'
    resources :threads do
      resources :replies
    end
  end

app/views/forum/reply/_form.html.haml

...
  - form_for [@thread, @reply] do |f|
...

app/controllers/forum/replies_controller.rb

...
  def new
    @reply = Forum::Reply.new
  end
...

错误

undefined method `forum_thread_forum_replies_path'

参考上面 _form.html.haml 中概述的行

In reference to the line outlined above in _form.html.haml

推荐答案

已编辑的解决方案,以防人们没有阅读反应:

Editted solution in case people don't read the reactions:

<%= form_for [:admin, @person, @image] do |f| %>

旧回复:

我有一个带有管理命名空间和 People 和 Images 资源的项目,这是我在 rails3 中构建 form_for 的方式,我还没有找到一种更简洁的方法......

I have a project with an admin namespace and People and Images resources, this is the way I build my form_for in rails3, I haven't found a way just yet to do it cleaner...

<%= form_for [@person, @image], :url => admin_person_images_path do |f| %>

这篇关于命名空间 form_for 中的嵌套资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆