我收到以下错误:
undefined method `recommendations_path' for #<#<Class:0x0078>>
我有推荐模型
class Recommendation < ActiveRecord::Base
belongs_to :user
belongs_to :recommended_user, class_name: "User", foreign_key: :recommended_user_id
end
我有用户模型
class User < ActiveRecord::Base
has_many :recommendations
................
end
在推荐控制器中
def new
@recommendation = current_user.recommendations.new
end
在new.html.erb
<%= form_for @recommendation do |f| %>
<%= f.text_field :relationship %>
<%= f.text_field :comment %>
<%= f.submit %>
<% end %>
我的路线,我认为问题在于:
devise_for :users
resources :users, only: [:show] do
collection do
get :customer_signup
get :employee_signup
end
member do
get :choose_role
get :become_a_customer
get :become_a_employee
end
end
resources :users do
resources :recommendations
end
答案 0 :(得分:2)
实际上,当表单试图识别@recommendation
的路径时。
根据您的routes.rb
,您的表单必须是:
<%= form_for [:user, @recommendation] do |f| %>