我现在面临这个错误很长一段时间了,我尝试了很多解决方案,但都没有奏效。让我的场景清晰:1)我没有使用脚手架命令并手动创建整个东西 2)错误是在尝试创建新的 Charity 时生成的
错误:
Showing /home/hitesh/Rails/ReachOut/app/views/charity/_form.html.erb where line #1 raised:
undefined method `charities_path' for #<#<Class:0x000000035ab3f8>:0x0000000344f220>
Extracted source (around line #1):
1: <%= form_for(@charity) do |f| %>
2: <% if @charity.errors.any? %>
3: <div id="error_explanation">
4: <h2><%= pluralize(@charity.errors.count, "error") %> THis is where i screwed prohibited this charity from being saved:</h2>
我的 _form.html.erb 看起来像这样:
<%= form_for(@charity) do |f| %>
<% if @charity.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@charity.errors.count, "error") %> THis is where i screwed prohibited this charity from being saved:</h2>
<ul>
<% @charity.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
MY routes.rb 包含慈善机构的条目
ReachOut::Application.routes.draw do
resources :charity
# The priority is based upon order of creation:
# first created -> highest priority.
我的慈善控制器:
class CharityController < ApplicationController
# GET /charity/new
# GET /charity/new.json
def new
@charity = Charity.new
respond_to do |format|
format.html #new.html.erb
format.json { render json: @charity}
end
end
和我的charity.rb(模型):确实包含一个慈善类
...
伙计们,我尝试了很多事情(更改@ => :),但仍然无法消除此错误...希望你们中的任何人都可以帮助我...我在整个系统中搜索了 charities_path 并且可以一无所获:) :(。