我有一个没有索引页面的调查模型。我只想要这个模型的编辑视图,但似乎 rails 不会让我这样做。undefined method surveys_path
当我尝试使用时它会抱怨form_for(@survey)
。无论如何在不创建空索引路由/视图的情况下执行此操作。
到目前为止,这是我的调查控制器
class SurveysController < ApplicationController
def show
@survey = Survey.find(params[:id])
end
def edit
@survey = Survey.new
job = Job.find(params[:id])
@survey.job_id = job.id
authorized_user = job.user
unless !is_runner?(current_login) && current_login.id == authorized_user.id
redirect_to jobs_path
end
end
def update
@survey = Survey.new(params[:survey])
end
end
这是在edit.html.erb中呈现的部分表单
<%= form_for(@survey) do |f| %>
<div class="field">
<%= f.label :speed %><br />
<%= f.text_field :speed %>
</div>
<div class="field">
<%= f.label :service %><br />
<%= f.text_field :service %>
</div>
<div class="field">
<%= f.label :suggestion %><br />
<%= f.text_area :suggestion %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>