【发布时间】:2013-06-03 02:17:16
【问题描述】:
我有一个没有索引页面的调查模型。我只想要这个模型的编辑视图,但似乎 rails 不会让我这样做。当我尝试使用form_for(@survey) 时,它会抱怨undefined method surveys_path。无论如何,在不创建空索引路由/视图的情况下这样做吗?
这是我目前的调查控制器
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 %>
【问题讨论】:
-
你可以试试这个:
form_for @survey, :url => survey_path(@post), :method => :put do...吗? -
我收到此错误
No route matches {:action=>"show", :controller=>"surveys", :id=>nil} -
您能发布您的路线吗?
标签: ruby-on-rails ruby ruby-on-rails-3 forms