I have the following:
Routes:
.
.
.
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 #model
class Relationship < ActiveRecord::Base
belongs_to :user
# TYPES = ['Family', 'Friend', 'Spouse']
end
I’ve hunted around on Stack Overflow and can’t seem to find the answer, although, I think it has something to do with nesting my resources. I get the following error:
undefined method 'relationships_path' for #<#<Class:0x007ff45f15ff80>:0x007ff45f15bc78>
Any ideas?
You should understand that all ‘_path’ helpers generated from route.rb file. So in your case route will generate this helper users_relationship_path for show action.
But in your form you’re using just form_for @relationship which is expected to use relationship_path helper.
So you should tell your form helper to use nesting, like this: