【发布时间】:2014-07-04 14:39:27
【问题描述】:
我的嵌套资源是农场。在我的路线中,我有:
resources :users do
resource :farm
end
devise_for :users, :path => 'accounts'
因此,注册等的设计路径正在工作并且没有产生问题。但是当我尝试创建一个新农场时,我收到了这个错误:
undefined method `farm_user_path' for #<#<Class:0x463d8f8>:0x46493e8>
我通过以下方式访问它:
<%= link_to "New Farm", new_user_farm_path(current_user) %>
在我的农场控制器中,我有:
class FarmsController < ApplicationController
# GET /farms
# GET /farms.json
include Devise::Controllers::Helpers
helper_method :current_user
def new
@farm = Farm.new
@user = User.find(current_user)
respond_to do |format|
format.html # new.html.erb
format.json { render json: @farm }
end
end
...
end
我制作新农场的形式是:
<%= form_for([@farm, @user]) do |f| %>
...
所有关联和路由都正常。我错过了什么?
【问题讨论】:
-
试试这样
<%= form_for([@user, @farm]) do |f| %> -
得到了基本相同的错误:#:0x2bbe148> 的未定义方法 `user_farms_path'
标签: ruby-on-rails forms nested