2

here's what I'm trying to do: Example of HAML/Rails thing I'm trying to do

That 'Request Key: ' part should actually be a 6-digit value, e.g.

Request Key: 614551

And the 'PCN: ' part is similar, it should be:

PCN: MEDDAET

Clicking on MEDDEAT would open a route that would search on that MEDDEAT value in the :foo_bar column.

The code I'm trying isn't working, and I don't know enough HAML to know why.

  %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.


EDIT: This is a HAMLC file. Coffeescript! GRRRRRR.....

Mike Earley
  • 1,223
  • 4
  • 20
  • 47
  • both examples in the answers below should have worked. I think you have error elsewhere on this page. Can you remove this line and check if you still have the error. Also perhaps you can post the stacktrace – Rajesh Sharma Jan 25 '16 at 19:26
  • The error appears to be in the coffeescript compilation of the hamlc file, and NOT in the code itself... – Mike Earley Jan 25 '16 at 19:27

4 Answers4

1
%li 
  Request Key: #{link_to @request.name, request_path(@request.name)}
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Tilo
  • 33,354
  • 5
  • 79
  • 106
  • this one, whether I put them on the same line or on separate lines (as you indicate) is giving me `SyntaxError: unmatched OUTDENT` – Mike Earley Jan 25 '16 at 18:51
  • In HAML you need to make sure that the indentation is correct. Please make sure that you use two space characters on each indentation level. – Tilo Jan 25 '16 at 19:44
1
 %li
   = "Request Key: #{link_to(@request.name, request_path(@request.name))".html_safe

this will works with rails

edikgat
  • 861
  • 8
  • 9
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/11024281) – Luca Detomi Jan 27 '16 at 08:09
  • @LucaDetomi How does this not provide an answer? It might be dead wrong, but it's not the kind of thing we should be deleting from review. – Undo Jan 27 '16 at 16:09
  • It was flagged as too short. Please provide details to let users understand "why" your solution could be a good one or maybe the best one. – Luca Detomi Jan 27 '16 at 16:11
0

Use:

%li
  Request Key:
  = link_to @request.name, request_path(@request.name)
Vasfed
  • 18,013
  • 10
  • 47
  • 53
0

Here was the answer, because it was HAMLC, not HAML (i.e. it compiles through coffeescript and not Rails, therefore Rails helpers didn't work).

  %li Request Key:
    %a{ :href => '/requests/#{ @name }', :target => '_blank'} #{@name}
Mike Earley
  • 1,223
  • 4
  • 20
  • 47