我有以下:未定義的方法`relationships_path」軌道3.1
途徑:
.
.
.
resources :users do
resources :relationships
end
new.html.erb:
<section id="main">
<%= form_for @relationship do |f| %> #This is the line the error is on
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<div class="actions"><%= f.submit %></div>
<% end %>
</section>
relationships_controller.rb
class RelationshipsController < ApplicationController
def new
@id = params[:user_id]
@rel_user = User.find_by_id(params[:user_id])
@relationship = Relationship.new
end
def create
end
end
relationship.rb#模型
class Relationship < ActiveRecord::Base
belongs_to :user
# TYPES = ['Family', 'Friend', 'Spouse']
end
我已經在Stack Overflow上尋找了,並且似乎找不到答案,但我認爲它與嵌套我的資源有關。我得到以下錯誤:
undefined method 'relationships_path' for #<#<Class:0x007ff45f15ff80>:0x007ff45f15bc78>
任何想法?
你嵌套在'relationship' ressources這樣的路徑變化。根據你以前的問題,運行'rake routes'來獲得解決方案。 – apneadiving
@apneadiving所以我看到我需要使用:new_user_relationship,但不是這一行的問題:'@relationship = Relationship.new'在我的控制器?我錯過了什麼? –