Devise嵌套资源视图未显示任何方法错误 [英] Devise nested resource view shows no method error

查看:60
本文介绍了Devise嵌套资源视图未显示任何方法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的嵌套资源是服务器场.在我的路线中,我有:

My nested resource is farm. In my routes I have:

resources :users do
  resource :farm
end


devise_for :users, :path => 'accounts'

因此,用于注册等的设计路径正在运行,并且没有出现问题.但是,当我尝试建立新服务器场时,出现此错误:

So, the devise paths for sign up, etc are working and not making problems. But when I try to make a new farm, I get this error:

undefined method `farm_user_path' for #<#<Class:0x463d8f8>:0x46493e8>

我正在通过以下方式访问它:

I am accessing it via:

<%= link_to "New Farm", new_user_farm_path(current_user) %>

在我的服务器场控制器中,我有:

In my farm controller, I have:

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

我制作新农场的表格是:

And my form for making new farm is :

<%= form_for([@farm, @user]) do |f| %>
...

所有关联和路由都可以.我想念什么?

All of the associations and routes are ok. What am I missing?

推荐答案

找到了解决方案.问题是我的表单需要如下所示:

Found the solution. Problem was that my form needed to look like this:

<%= form_for([@user, @farm], :url=> new_user_farm_path(@user)) do |f| %>

这篇关于Devise嵌套资源视图未显示任何方法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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