如何在Rails的链接的href值中插入变量? [英] how can i insert a variable in to a href value in a link in rails?

查看:61
本文介绍了如何在Rails的链接的href值中插入变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

  <a href="/patients/#{@appointment.patient.id}">
  <%=h @appointment.patient.f_name %> <%=h @appointment.patient.l_name%>
  </a>

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

but it dose not work due to a syntax error, if i click on the href it goes to http://0.0.0.0:3000/patients/#{@appointment.patient.id}

谢谢

推荐答案

您可以执行以下操作:

<a href="/patients/<%= @appointment.patient.id %>">

但是使用 link_to 通常更容易:

But it's generally easier to use link_to:

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

这篇关于如何在Rails的链接的href值中插入变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆