Question

I created this route:

get "patientform/create/(:department_id)/(:form_model)/(:form_id)/(:formpath)", to: 'patientform#create', as: 'create_patientform'

Later i call it in my view:

<%= link_to 'Form', create_patientform_path(@current_department.id, @patient.class.name, nil, "patients.form"), :class => 'btn btn-info btn-xs' %>

How you can see in my link :form_id is defined as nil This creates this link:

http://localhost:3000/patientform/create/2/Patient/patients.form

But i would need this link:

http://localhost:3000/patientform/create/2/Patient//patients.form

Becaus in my controller i save it like this:

   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

How you can see the false link provokes that later not the form_id is saved as nil but insted formpath is 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">
Was it helpful?

Solution

Just modify your routes as

get "patientform/create/(:department_id)/(:form_model)/(:formpath)/(:form_id)", to: 'patientform#create', as: 'create_patientform'

and your link_to to

<%= link_to 'Form', create_patientform_path(@current_department.id, @patient.class.name, "patients.form", nil), :class => 'btn btn-info btn-xs' %>

so that it takes the form_path first and then the form_id

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top