形成部分错误:#&lt;#<class:0x3ed3078>的未定义方法`experiments_path':0x3313200&gt; </class:0x3ed3078>

时间:2014-03-24 00:07:49

标签: ruby-on-rails ruby-on-rails-3 controller partials

我找不到我在这里做错了什么,有什么我想念的吗?

我的新动作/视图:

<h1>Submit a new experiment here!</h1>

<%= render "form" %>

我的_form.html.erb表单部分

<h1>THis is a form</h1>

<%= form_for(@experiment) do |f| %>
  <div class="field">
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </div>
  <div class="field">
    <%= f.label :description %><br />
    <%= f.text_field :description %>
  </div>
  <div class="field">
    <%= f.label :plan %><br />
    <%= f.text_field :plan %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

我的实验控制器:

class ExperimentController < ApplicationController

    def index
    end

    def new
    @experiment = Experiment.new
    end

end

我的路线:

  devise_for :users
  resources :home
  resources :experiment

  root to: "home#index"

我正在访问以下网址:

http://localhost:3000/experiment/new

1 个答案:

答案 0 :(得分:0)

如果您想遵循rails convention,那么:

  1. 将您的控制器从ExperimentController重命名为ExperimentsController,即复数Experiments
  2. 将控制器文件名app/controllers/experiment_controller.rb重命名为app/controllers/experiments_controller.rb,即复数experiments_controller.rb
  3. 通过将resources :experiment修改为resources :experiments来更新您的路线。
  4. 如果没有,请将您的form_for来电更新为:

    <%= form_for(@experiment, url: url_for(controller: 'experiment', action: 'create')) do |f| %>
      ...
    <% end %>