我找不到我在这里做错了什么,有什么我想念的吗?
我的新动作/视图:
<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
答案 0 :(得分:0)
如果您想遵循rails convention,那么:
ExperimentController
重命名为ExperimentsController
,即复数Experiments
。 app/controllers/experiment_controller.rb
重命名为app/controllers/experiments_controller.rb
,即复数experiments_controller.rb
。resources :experiment
修改为resources :experiments
来更新您的路线。如果没有,请将您的form_for
来电更新为:
<%= form_for(@experiment, url: url_for(controller: 'experiment', action: 'create')) do |f| %>
...
<% end %>