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

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

问题描述

问题

form_for帮助程序错误地确定了我在命名空间内的嵌套资源的路径.有问题的模型分别是: Forum :: Thread Forum :: 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/replies/_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 and 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天全站免登陆