我创建了这条路线:
get "patientform/create/(:department_id)/(:form_model)/(:form_id)/(:formpath)", to: 'patientform#create', as: 'create_patientform'
后来我在我的观点中称之为:
<%= link_to 'Form', create_patientform_path(@current_department.id, @patient.class.name, nil, "patients.form"), :class => 'btn btn-info btn-xs' %>
如何在我的链接:form_id
中看到被定义为nil
这会创建此链接:
http://localhost:3000/patientform/create/2/Patient/patients.form
但我需要这个链接:
http://localhost:3000/patientform/create/2/Patient//patients.form
我的控制器中的Becaus我这样保存:
def create
a = Patientform.new
a.secure = SecureRandom.hex 3
a.department_id = params[:department_id]
a.form_id = params[:form_id]
a.form_model = params[:form_model]
a.formpath = params[:formpath]
if a.save
flash[:notice] = "Patienten Formular jetzt vefügbar zu finden unter #{a.secure}"
redirect_to :back
end
end
如何看到错误链接会引发以后form_id
未保存为nil
但formpath
已nil
=> #<Patientform id: 4, department_id: "2", form_model: "Patient", form_id: "pat
ients.form", secure: "f7a58b", formpath: nil, created_at: "2013-11-15 11:19:53", upda
ted_at: "2013-11-15 11:19:53">
答案 0 :(得分:0)
只需将路线修改为
即可get "patientform/create/(:department_id)/(:form_model)/(:formpath)/(:form_id)", to: 'patientform#create', as: 'create_patientform'
和您的link_to
到
<%= link_to 'Form', create_patientform_path(@current_department.id, @patient.class.name, "patients.form", nil), :class => 'btn btn-info btn-xs' %>
这样首先需要form_path
,然后是form_id