简体   繁体   English

Rails,HAML,使用link_to

[英]Rails, HAML, using a link_to

here's what I'm trying to do: 这是我想要做的: 我尝试做的HAML / Rails事例

That 'Request Key: ' part should actually be a 6-digit value, eg 'Request Key: '部分实际上应该是6位数字的值,例如

Request Key: 614551 请求密钥: 614551

And the 'PCN: ' part is similar, it should be: 'PCN: '部分相似,应该是:

PCN: MEDDAET PCN: MEDDAET

Clicking on MEDDEAT would open a route that would search on that MEDDEAT value in the :foo_bar column. 单击MEDDEAT将打开一条路由,该路由将在:foo_bar列中搜索该MEDDEAT值。

The code I'm trying isn't working, and I don't know enough HAML to know why. 我正在尝试的代码无法正常工作,而且我对HAML的了解不足,无法知道原因。

  %li Request Key: = link_to #{@request.name}, request_path(@request.name)

and

  %li = link_to "request.pcn", :controller => filter_plans,  :q => {:plan_aliases_PlanAlias_cont => @pcn}}

As you can se, that code just renders as text, not a link. 如您所知,该代码仅呈现为文本,而不是链接。 I'd appreciate help on what I'm doing wrong here with the HAML code. 感谢您对我在这里使用HAML代码做错的事情的帮助。


EDIT: This is a HAMLC file. 编辑:这是一个HAMLC文件。 Coffeescript! CoffeeScript的! GRRRRRR..... GRRRRRR .....

%li 
  Request Key: #{link_to @request.name, request_path(@request.name)}

Use: 采用:

%li
  Request Key:
  = link_to @request.name, request_path(@request.name)
 %li
   = "Request Key: #{link_to(@request.name, request_path(@request.name))".html_safe

this will works with rails 这将适用于导轨

Here was the answer, because it was HAMLC, not HAML (ie it compiles through coffeescript and not Rails, therefore Rails helpers didn't work). 答案就在这里,因为它是HAMLC,而不是HAML(即,它是通过coffeescript而不是Rails进行编译的,因此,Rails帮助器无法工作)。

  %li Request Key:
    %a{ :href => '/requests/#{ @name }', :target => '_blank'} #{@name}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM