Devise nested resource view shows no method error

点点圈 提交于 2019-12-06 15:14:14

问题


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?


回答1:


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| %>


来源:https://stackoverflow.com/questions/24576654/devise-nested-resource-view-shows-no-method-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!