how can i insert a variable in to a href value in a link in rails?

房东的猫 提交于 2019-12-10 15:21:16

问题


i have:

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

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}

thanks


回答1:


You can do:

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

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)


来源:https://stackoverflow.com/questions/3367776/how-can-i-insert-a-variable-in-to-a-href-value-in-a-link-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!