如何将变量插入到rails中的链接中的href值?

Mo.*_*Mo. 4 ruby-on-rails erb

我有:

  <a href="/patients/#{@appointment.patient.id}">
  <%=h @appointment.patient.f_name %> <%=h @appointment.patient.l_name%>
  </a>
Run Code Online (Sandbox Code Playgroud)

但由于语法错误,它不起作用,如果我点击href它去 http://0.0.0.0:3000/patients/#{@appointment.patient.id}

谢谢

Sha*_*ell 13

你可以做:

<a href="/patients/<%= @appointment.patient.id %>">
Run Code Online (Sandbox Code Playgroud)

但它通常更容易使用link_to:

link_to(@appointment.patient.f_name + " " + @appointment.patient.l_name, 
        :controller => 'patients', :action => 'show', :id => @appointment.patient.id)
Run Code Online (Sandbox Code Playgroud)