1

私はかなり長い間このエラーに直面しています。多くの解決策を試しましたが、どれも機能していません。シナリオを明確にする: 1) scaffold コマンドを使用しておらず、全体を手動で作成している 2) 新しいチャリティーを作成しようとするとエラーが生成される

エラー:

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

および My charity.rb (MODEL) :慈善クラスが含まれています

...

みんな私;多くのことを試しました(@ => :)を変更しましたが、まだこのエラーを削除できません...誰かが私を助けてくれることを願っています...システム全体でcharities_pathを検索し、できました何も見つかりません:) :(。

4

1 に答える 1

3

あなたresources :charitiesはroutes.rbで必要です

また、コントローラーにはCharitiesControllerという名前を付ける必要があります

または、パスヘルパーメソッドを手動で設定する必要がありますが、この場合、別の問題に直面する可能性があります。レールの命名規則に従うことをお勧めします。

于 2012-04-22T09:33:46.193 に答える