开发者

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

开发者 https://www.devze.com 2023-01-09 06:13 出处:网络
i have: <a href=\"/patients/#{@appointment.patient.id}\"> <%开发者_运维技巧=h @appointment.patient.f_name %> <%=h @appointment.patient.l_name%>

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


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消