简体   繁体   English

Rails表单给出了未定义的方法错误

[英]Rails form is giving undefined method error

This seems like such an easy question, but I can't figure out what I'm doing wrong. 这似乎是一个简单的问题,但我无法弄清楚我做错了什么。 I have the following form code: 我有以下表单代码:

In the controller: 在控制器中:

class ProjectApplicationsController < ApplicationController
    def new_project
        @project.new
        @referral = Referral.new
    end
end

In the view: 在视图中:

<%= form_for @referral do |f| %>
    <%= f.text_field :referrer_email %>
<% end %>

Routes File: 路线文件:

resources :referalls, only: [:create]

I have done this countless times before, the only difference being that the view the form is rendered from is different from the controller it is going to(the form should go to referrals#create). 我以前做过无数次这样做,唯一的区别是表单的呈现方式不同于它要进行的控制器(表单应该转到引用#create)。 For some reason I get the error: 出于某种原因,我得到错误:

undefined method `referrals_path' for #<#<Class:0x007fba5a11b4a0>:0x007fba5a119a10>

What am I doing wrong? 我究竟做错了什么?

You are getting this error because there is no referrals_path. 您收到此错误,因为没有referrals_path。 You have double l in referalls 在referalls中你有双倍的l

resources :referalls, only: [:create] 

but it should be 但它应该是

resources :referrals, only: [:create]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 simple_form为Rails 4中的嵌套路由的#&lt;#提供错误的未定义方法`reviews_path&#39; - simple_form is giving error undefined method `reviews_path' for #<# for nested route in Rails 4 Rails用户类对方法无响应,给出未定义的方法错误 - Rails user class no responding to method, giving undefined method error Rails验证错误消息未显示,并提供未定义的方法错误 - Rails validation error message is not showing and is giving undefined method error 联系人表格邮件未定义方法错误 - Contact Form Mailer Undefined Method Error Rails 联系表格未定义方法错误 - Contact Form Undefined Method Error Rails Rails:如何更正表单上未定义的方法错误? - Rails : How to correct undefined method error on form? Rails嵌套的属性给出错误:未定义的方法“ build_priority” - Rails nested attributes giving error: undefined method `build_priority' Rails 测试给我一个错误“未定义的方法 &#39;body&#39;” - Rails test giving me an error of “undefined method 'body' ” Active Admin:在Rails 4中,longate_to提供“未定义的方法”错误 - Active Admin: belongs_to giving “undefined method” Error in Rails 4 Rails omniauth和常规登录,给出未定义的方法错误 - Rails omniauth and regular login, giving an undefined method error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM