Karthik T
Karthik T

Reputation: 31952

Slim Link to tag with block contents behaving oddly

When I do

= link_to "/venue/XYZ"
  .content
    ...

It works correctly and the contents are inside the link tag.

But when I do

= link_to venue_path("XYZ")
  .content
    ...

The contents appear to be lost and all I get is

<a href="http://localhost/home/search">
    /venue/XYZ
</a>

I am not sure why this is happening.. I have tried with the do at the end of link_to as well. /home/search is the current controller/action

Edit:

- s = venue_path("XYZ").to_s
= link_to s
  .content
    ...

Works.. am not sure whats happening anymore...

Upvotes: 2

Views: 564

Answers (1)

phts
phts

Reputation: 3925

You missed do word.

Correct syntax:

= link_to venue_path("XYZ") do
  .content

do is a required statement when the block is passed. Seems link_to to work in an unpredictable way if you pass a block without do (how could it work at all? o_O).

http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to

Upvotes: 1

Related Questions